Alertdialog in Android uses example three (one-way selection OK dialog box)

Source: Internet
Author: User

In Android development, we often need to pop up some dialog boxes on the Android interface, such as asking the user or letting the user choose. These features we call it Android Dialog dialog box, Alertdialog implementation method for Builder mode. Below we simply simulate a selection of a daughter-in-law to determine the dialog box (Radio) dialog box, unlike the example of the second point is that this time as long as the uncertainty can be regretted oh, such as:

Layout Interface Code:

  1  <?xml version= "1.0" encoding= "Utf-8"?>  2  <linearlayout xmlns:android= "http://schemas.android.com/apk/res/android " 3  android:orientation=" vertical "android:layout_width=" match_parent " 4  android:layout_height= "match_parent" > 5  &L T button   6  android:text= "One-way Selection"  7  android:l Ayout_width= "Match_parent"  8  android:layout_height= "Wrap_content"  9  android:onclick= "show3" 10  android:id= "@+id/ Button3 "/>11  </linearlayout> 

Java feature Implementation code:

1  Public classAlertdialogdemoextendsappcompatactivity {2     intIndex=0;3 @Override4     protected voidonCreate (@Nullable Bundle savedinstancestate) {5         Super. OnCreate (savedinstancestate);6 Setcontentview (r.layout.alertdialog);7     }8      Public voidshow3 (View v) {9Alertdialog.builder Builder =NewAlertdialog.builder ( This);TenBuilder.settitle ("Pick a daughter-in-law son"); One         FinalString[] Beautifulgirls = {"Sister Furong", "Chicken Sister", "Fan ye", "Myself"}; ABuilder.setsinglechoiceitems (beautifulgirls, 0,NewDialoginterface.onclicklistener () { - @Override -              Public voidOnClick (Dialoginterface Dialog,intwhich) { theindex =which; -             } -         }); -Builder.setpositivebutton ("OK",NewDialoginterface.onclicklistener () { + @Override -              Public voidOnClick (Dialoginterface Dialog,intwhich) { +Toast.maketext (Alertdialogdemo. This, beautifulgirls[index]+, "It's your daughter-in-law.", Toast.length_short). Show (); A             } at         }); - builder.show (); -     } -}

The optimization space is very big, everybody can play.

Alertdialog in Android uses example three (one-way selection OK dialog box)

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.