Use of the <Android> dialog box

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.