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)