The Android system provides four dialog boxes: Warning dialog (Alertdialog), progress Dialog (ProgressDialog), Date selection dialog (Datepickerdialog) and Time Selection dialog (Timepickerdialog). The focus here is on Alertdialog.
1. Gets the static internal class builder object for Alertdialog, which is created by the class to create a dialog box
2. Use the Builder object to set the caption of the dialog box, the button and the event that the button will respond to
3. Call Builder's Create () method Creation dialog box
4. Call the show () method of Alertdialog to display the dialog box.
Alertdialog.builder Builder =NewAlertdialog.builder ( This); Builder.setmessage (msg). Setcancelable (false). Setpositivebutton ("OK",NewDialoginterface.onclicklistener () { Public voidOnClick (Dialoginterface Dialog,intID) {finish (); }}). Setnegativebutton ("Cancel",NewDialoginterface.onclicklistener () { Public voidOnClick (Dialoginterface Dialog,intID) {return; } }); Alertdialog Alert=builder.create (); Alert.show ();
You can also set multiple entry options as a context for the user to select
string[] items = {"Orleans chicken leg fort", "Spicy chicken leg fort", "coffee"}; Alertdialog.builder Builder=NewAlertdialog.builder ( This);//Builder.settitle ("Please Order"). Setitems (Items, new Dialoginterface.onclicklistener () {//If you change to the following method, display it as a single button styleBuilder.settitle ("Please order"). Setsinglechoiceitems (Items,-1,NewDialoginterface.onclicklistener () { Public voidOnClick (Dialoginterface Dialog,intwhich) {Mytv.settext (Items[which]); }}); Alertdialog AD=builder.create (); Ad.show ();
Use of the <Android> dialog box