Checkbox In Alertdialog "pushed Out" By Textview
I'm trying to create an AlertDialog to show an introduction message in my application, with a 'Don't show this again' CheckBox below it. It works well when the message of the Alert
Solution 1:
Don't set the dialog box message, instead include it in the layout XML as textView.
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical"><TextViewandroid:id="@+id/message"android:layout_width="wrap_content"android:layout_height="wrap_content"android:singleLine="false"android:maxLines="3"android:scrollbars="vertical"/><CheckBoxandroid:id="@+id/checkBox"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Don't show this again"></CheckBox></LinearLayout>
Solution 2:
Use the XML layout from the answer earlier.
StringlongMessage= getString(R.string.long_message);
LayoutInflaterinflater= getLayoutInflater();
finalViewcheckboxLayout= inflater.inflate(R.layout.dont_show_again, null);
CheckBoxcb= (CheckBox)checkboxLayout.findViewById(R.id.checkBox);
TextViewtv= (TextView)checkboxLayout.findViewById(R.id.message);
tv.setText(longMessage);
AlertDialog.Builderbuilder=newAlertDialog.Builder(this)
.setTitle("Some message")
.setView(checkboxLayout)
.setPositiveButton("Ok",
newDialogInterface.OnClickListener() {
publicvoidonClick(DialogInterface dialog, int which) {
}
});
AlertDialogdialog= builder.create();
dialog.show();
Post a Comment for "Checkbox In Alertdialog "pushed Out" By Textview"