Android Development using Alertdialog Create dialog boxes, radio boxes and multi-marquee

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.