dialog box:
Code:
1 Public voidClick (View v) {2Alertdialog.builder Builder =NewAlertdialog.builder ( This);3 Builder.seticon (Android. R.drawable.alert_dark_frame);4Builder.settitle ("The nosebleed is frugal");5Builder.setmessage ("Yin Zhiping, please think well!!! ");6Builder.setpositivebutton ("OK",NewOnclicklistener () {7 8 @Override9 Public voidOnClick (Dialoginterface Dialog,intwhich) {TenToast.maketext (mainactivity. This, "Thanks for using the software, close", 0). Show (); One } A }); - -Builder.setnegativebutton ("Cancel",NewOnclicklistener () { the - @Override - Public voidOnClick (Dialoginterface Dialog,intwhich) { -Toast.maketext (mainactivity. This, "no womb, certainly not successful", 0). Show (); + } - }); + A builder.show (); at}
Radio Box:
Use the Setsinglechoiceitems () method to set the radio
Builder.setsinglechoiceitems (charsequence[] items, int checkeditem, Onclicklistener listener)
Parameters:
1.items: Array of radio options defined
2.checkedItem: The option is selected by default. By default unchecked is-1, check array first is 0, check array second is 1, select array Third is 2
3.listener: Listener
New Onclicklistener () {...}. OnClick (dialoginterface dialog, int which)
Code:
1 Public voidClick1 (View v) {2Alertdialog.builder Builder =NewAlertdialog.builder (mainactivity. This);3 Builder.seticon (Android. R.drawable.alert_dark_frame);4Builder.settitle ("The nosebleed is frugal");5 Finalstring[] Items =NewString[] {"Female", "male" };6Builder.setsinglechoiceitems (items,-1,NewOnclicklistener () {7 8 @Override9 Public voidOnClick (Dialoginterface Dialog,intwhich) {TenToast.maketext (mainactivity. This, "Selected:" + Items[which], 0) One . Show (); A Dialog.dismiss (); - } - }); the builder.show (); -}
Multi Box:
Code:
1 Public voidClick2 (View v) {2Alertdialog.builder Builder =NewAlertdialog.builder ( This);3 Builder.seticon (Android. R.drawable.alert_dark_frame);4Builder.settitle ("Please select multiple options");5 Finalstring[] Items =NewString[] {"Marten Cicada", "Xi Shi", "director", "Design", "development" };6 Final Boolean[] CheckedItems =New Boolean[] {false,false,false,7 false,false };8 builder.setmultichoiceitems (items, CheckedItems,9 NewOnmultichoiceclicklistener () {Ten One @Override A Public voidOnClick (Dialoginterface Dialog,intwhich, - BooleanisChecked) { -Checkeditems[which] =isChecked; the } - }); -Builder.setpositivebutton ("OK",NewOnclicklistener () { - + @Override - Public voidOnClick (Dialoginterface Dialog,intwhich) { + AString Text = ""; at for(inti = 0; i < items.length; i++) { - if(Checkeditems[i]) { -Text + =Items[i]; - } - } -Toast.maketext (mainactivity. This, text, 0). Show (); in Dialog.dismiss (); - to } + }); - builder.show (); the}
Android Development using Alertdialog Create dialog boxes, radio boxes and multi-marquee