The first is the confirmation dialog box
Confirm dialog box private void ShowLog1 () { alertdialog.builder dialog = new Alertdialog.builder (this); Dialog.settitle ("Tsinghua University"); Set the title Dialog.seticon (r.mipmap.ic_launcher);//Set Picture dialog.setmessage ("Confirm to apply for Tsinghua University?") "); Set content Dialog.setpositivebutton ("Confirm", new Dialoginterface.onclicklistener () {//Confirm Anne @Override Public void OnClick (Dialoginterface dialog, int which) { toast.maketext (mainactivity.this, "You're Awesome", toast.length_short). Show (); } }); Dialog.setnegativebutton ("Cancel", new Dialoginterface.onclicklistener () {//Cancel button @Override public Void OnClick (dialoginterface dialog, int which) { toast.maketext (mainactivity.this, "True Pity", Toast.length_short). Show ( ); } }); Dialog.show ();//Don't forget to show the dialog box out }
Single-selection dialog box
Radio dialog box private void ShowLog2 () { alertdialog.builder dialog = new Alertdialog.builder (this); Dialog.settitle ("Choose Gender"); Dialog.seticon (r.mipmap.ic_launcher); Dialog.setsinglechoiceitems (Sex, 0, new Dialoginterface.onclicklistener () { @Override public void OnClick ( Dialoginterface dialog, int which) { String str = Sex[which]; Toast.maketext (Mainactivity.this, "You have selected" +str, Toast.length_short). Show (); } ); Dialog.show (); }
Multi-Select dialog box
List dialog box
The list dialog box private void ShowLog4 () { alertdialog.builder dialog = new Alertdialog.builder (this); Dialog.settitle ("hobby list"); Dialog.seticon (r.mipmap.ic_launcher); Dialog.setitems (item, new Dialoginterface.onclicklistener () { @Override public void OnClick (dialoginterface dialog, int which) { toast.maketext (mainactivity.this, "I Like" +item[which]+ "!", Toast.length_short). Show (); }); Dialog.show (); }
android dialog Box dialog