Recently in the project, the group of several back home. Interface for the moment no one to do, use the custom dialog box can only temporarily to learn. Now put the dialog box related to the collation.
<relativelayout 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:paddi ngbottom= "@dimen/activity_vertical_margin" android:paddingleft= "@dimen/activity_horizontal_margin" Android: paddingright= "@dimen/activity_horizontal_margin" android:paddingtop= "@dimen/activity_vertical_margin" tools: context= "Com.example.alertdialog.MainActivity" > <button android:id= "@+id/button1" Android:layout_w Idth= "Fill_parent" android:layout_height= "Wrap_content" android:layout_alignparenttop= "true" Android: Layout_centerhorizontal= "true" android:text= "Show alertdialog dialog box"/> <button android:id= "@+id/button2" Android:layout_width= "Fill_parent" android:layout_height= "wrap_content" android:layout_below= "@+id/b Utton1 "android:text=" Display list dialog box "/> <button Android:id= "@+id/button3" android:layout_width= "fill_parent" android:layout_height= "Wrap_content" android:layout_below= "@+id/button2" android:text= "Show Radio List dialog box"/> <button android:id= "@+id/button4" Android:layout_width= "Fill_parent" android:layout_height= "wrap_content" android:layout_below= "@+id/but Ton3 "android:text=" Display multi-Select Dialog "/> <button android:id=" @+id/button5 "android:layout_width=" fill _parent "android:layout_height=" wrap_content "android:layout_below=" @+id/button4 "android:layout_cent Erhorizontal= "true" android:text= "Call resource File Multi-select Dialog"/></relativelayout>
Package Com.example.alertdialog;import Android.app.activity;import Android.app.alertdialog;import Android.content.dialoginterface;import Android.view.view.onclicklistener;import Android.os.Bundle;import Android.view.view;import Android.widget.button;import Android.widget.toast;public class MainActivity extends Activity {Private button Button1;private button button2;private Final charsequence[] items = {"Guangzhou", "Shenzhen", "Shanghai", "Beijing"}; priva Te button button3;private button button4;private button button5; @Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.main); button1 = (Button) Findviewbyid (r.id.button1); button2 = (Button) Findviewbyid (r.id.button2); button3 = (Button) Findviewbyid ( R.ID.BUTTON3); button4 = (Button) Findviewbyid (r.id.button4); button5 = (Button) Findviewbyid (R.ID.BUTTON5); Button1.setonclicklistener (New Onclicklistener () {public void OnClick (view view) {Alertdialog.builder Builder = new Aler Tdialog.builder (MainactiviTy.this); Builder.settitle ("hint"); Builder.setmessage ("Are you sure you want to delete it!"); Builder.seticon (R.drawable.ic_launcher); Builder.setpositivebutton ("OK", new Dialoginterface.onclicklistener () { public void OnClick (dialoginterface dialog, int arg1) {//Let the dialog box disappear Dialog.dismiss ();}); Builder.setnegativebutton ("Cancel", new Dialoginterface.onclicklistener () {public void OnClick (dialoginterface arg0, int ARG1) {//TODO auto-generated Method stub}}); Builder.setneutralbutton ("Ignore", new Dialoginterface.onclicklistener () {@ overridepublic void OnClick (dialoginterface arg0, int arg1) {//TODO auto-generated method stub//Ignore user action, function and cancel the same}}); Alertdialog Alertdialog = Builder.create (); Alertdialog.show ();}); Button2.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View arg0) {//TODO auto-generated Method Stubalertdialog.builder Builder = new Alertdialog.builder (mainactivity.this); Builder.settitle ("hint");// Can not set the content of the setmessage, or will overwrite the value of the original item//before onclicklistener to add Dialoginterface, or will error Builder.setitems (items, new DiAloginterface.onclicklistener () {@Overridepublic void OnClick (dialoginterface arg0, int index) {//item[index] Can not be converted to a string, converted to charsequence on the line charsequence Select_item = Items[index]; Toast.maketext (Mainactivity.this, "you selected the City" +select_item, 1). Show ();}); Alertdialog Alertdialog = Builder.create (); Alertdialog.show ();}); Button3.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View arg0) {//TODO auto-generated Method Stubalertdialog.builder Builder = new Alertdialog.builder (mainactivity.this); Builder.settitle ("Please select the following cities"); Builder.seticon (R.drawable.ic_launcher);/* First parameter: Display in dialog box for select list * Second parameter: Default selected value, 1 means none selected * Third parameter: Listener */Builder . Setsinglechoiceitems (items,-1, New Dialoginterface.onclicklistener () {@Overridepublic void OnClick (dialoginterface dialog, int which) {//TODO auto-generated method Stubcharsequence Select_item = Items[which]; Toast.maketext (Mainactivity.this, "-->>" +select_item, 1). Show ();d Ialog.dismiss ();}); Alertdialog Alertdialog = builder.cReate (); Alertdialog.show ();}}); Button4.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View arg0) {Alertdialog.builder Builder = new Alertdialog.builder (mainactivity.this); Builder.settitle ("Please select the following cities");/* * First parameter: Select multiple selection list * Second parameter: An array of type Boolean that represents the selected item, or, if set to NULL, indicates that no option is selected by default * The third parameter: Needless to say, listener */builder.setmultichoiceitems (items, new boolean[]{ False,false,true,false}, new Dialoginterface.onmultichoiceclicklistener () {@Overridepublic void OnClick ( Dialoginterface arg0, int arg1, Boolean ischecked) {//TODO auto-generated Method stub}}); Builder.setpositivebutton ("OK" , new Dialoginterface.onclicklistener () {@Overridepublic void OnClick (dialoginterface arg0, int arg1) {//Get the selected value directly}}); Alertdialog Alertdialog = Builder.create (); Alertdialog.show ();}); /is actually another way of Button4 Button5.setonclicklistener (new Onclicklistener () {@Overridepublic void OnClick (View arg0) { Alertdialog.builder Builder = new Alertdialog.builder (mainactivity.this); Builder.settitle ("Please select the following cities");//Get selection values: using StRingbuffer appended, separated by commas Builder.setmultichoiceitems (r.array.city, New Boolean[]{false,false,true,false}, new Dialoginterface.onmultichoiceclicklistener () {public void OnClick (dialoginterface arg0, int arg1, Boolean arg2) {//TODO auto-generated method stub}}); Builder.setpositivebutton ("OK", new Dialoginterface.onclicklistener () {public void OnClick (dialoginterface arg0, int arg1) {//Get the selected Value}}); Alertdialog Alertdialog = Builder.create (); Alertdialog.show ();}});}
android dialog box (i) Alertdialog