:
XML file:
Create a Click button and add a click Method:
<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools " android:layout_width=" match_parent " android:layout_height=" Match_parent " android:orientation= "vertical" tools:context= ". Mainactivity "> <button android:id=" @+id/button1 " android:layout_width=" Fill_parent " android:layout_height= "Wrap_content" android:onclick= "Showalertdialog" android:text= "AlertDialog"/ ></LinearLayout>
Mainactivity: Implementation of Click Button Monitoring method
public void Showalertdialog (view view) {/* * Set Radio items * */alertdialog.builder Builder = new Alertdialog.builder (mainactiv Ity.this);//internal Use builder's design mode final string[] items = {"Apple", "orange", "Banana"};builder.settitle ("Dialog"); Builder.setsinglechoiceitems (items, -1,new Onclicklistener () {///The second parameter is set by default which item is selected-1 means no @overridepublic void is selected by default OnClick (dialoginterface dialog, int which) {//TODO auto-generated method Stubtoast.maketext (Mainactivity.this, items[ which], 0). Show ();}}); Builder.setcancelable (false);///Settings dialog can only be exited by clicking the button on the dialog, unable to exit the close Dialogbuilder.create () by a fallback button. Show (); /Create Object}
Android adds a radio button "define dialog" in dialog