The examples in this article describe the use of the Android check Box dialog box. Share to everyone for your reference. Specifically as follows:
Main.xml Layout file
<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android=
"http://schemas.android.com/apk/" Res/android "
android:orientation=" vertical "android:layout_width=" fill_parent "
android:layout_height=" Fill_parent ">
<edittext android:text=" "
android:id=" @+id/edittext "
android:layout_width=" fill _parent "
android:layout_height=" wrap_content "
android:editable=" false "
android:cursorvisible=" False "/>
<button android:text=" Displays check box dialog "
android:id=" @+id/button "
android:layout_width=" Fill_parent "
android:layout_height=" wrap_content "/>
</LinearLayout>
Array.xml Array
<?xml version= "1.0" encoding= "Utf-8"?>
<resources>
<string-array name= "hobby" >
< item> Swimming </item>
<item> playing basketball </item>
<item> mountaineering </item>
</string-array >
</resources>
Alertactivity class
Package com.ljq.dialog;
Import android.app.Activity;
Import Android.app.Dialog;
Import Android.app.AlertDialog.Builder;
Import Android.content.DialogInterface;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.widget.Button;
Import Android.widget.EditText;
public class Alertdialog extends activity {private EditText edittext;
Private final static int dialog=1;
Boolean[] flags=new boolean[]{false,false,false};//initial check string[] items=null;
@Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
Items=getresources (). Getstringarray (R.array.hobby);
edittext= (EditText) Findviewbyid (R.id.edittext);
Button button = (button) Findviewbyid (R.id.button); Button.setonclicklistener (New View.onclicklistener () {public void OnClick (View v) {//Display dialog box ShowDialog (DIALOG
);
}
});
/** * Create check box dialog box/@Override protected Dialog oncreatedialog (int id) {Dialog dialog=null; SwiTCH (ID) {case dialog:builder builder=new android.app.AlertDialog.Builder (this);
Set the icon for the dialog box Builder.seticon (R.drawable.header);
Sets the title Builder.settitle (CheckBox dialog box) for the dialog box; Builder.setmultichoiceitems (R.array.hobby, Flags, new Dialoginterface.onmultichoiceclicklistener () {public void
OnClick (dialoginterface dialog, int which, Boolean ischecked) {flags[which]=ischecked;
String result = "You have selected:";
for (int i = 0; i < flags.length i++) {if (flags[i)) {result=result+items[i]+ ",";
} edittext.settext (result.substring (0, Result.length ()-1));
}
}); Add a OK button Builder.setpositivebutton (OK), new Dialoginterface.onclicklistener () {public void OnClick (Dialoginte
Rface dialog, int which) {}});
Create a check box dialog box Dialog=builder.create ();
Break
return dialog;
}
}
Run Result:
I hope this article will help you with your Android program.