我正在尝试创建一个AlertDialog以在我的应用程序中显示一个介绍消息,并在其下面带有一个“不再显示此内容”复选框。
当AlertDialog的消息很短,但是太长(需要滚动)时,它不再显示CheckBox。它通过TextView被“推出”。
自定义视图的XML(dont_show_again.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Don't show this again">
</CheckBox>
</LinearLayout>
以及显示AlertDialog的代码
String longMessage = getString(R.string.long_message);
LayoutInflater inflater = getLayoutInflater();
final View checkboxLayout = inflater.inflate(R.layout.dont_show_again, null);
AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setTitle("Some message")
.setMessage(longMessage)
.setView(checkboxLayout)
.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog dialog = builder.create();
dialog.show();
关于如何解决此问题的任何想法?也许有人举了一个带有“不再显示此内容”复选框的AlertDialog的示例?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<TextView
android:id="@+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="false"
android:maxLines="3"
android:scrollbars="vertical"/>
<CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Don't show this again">
</CheckBox>
</LinearLayout>
String longMessage = getString(R.string.long_message);
LayoutInflater inflater = getLayoutInflater();
final View checkboxLayout = inflater.inflate(R.layout.dont_show_again, null);
CheckBox cb = (CheckBox)checkboxLayout.findViewById(R.id.checkBox);
TextView tv = (TextView)checkboxLayout.findViewById(R.id.message);
tv.setText(longMessage);
AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setTitle("Some message")
.setView(checkboxLayout)
.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog dialog = builder.create();
dialog.show();