Android dialog box-previous-system dialog box

Source: Internet
Author: User

1. Android has four default dialog implementations: alertdialog, progressdialog, datepickerdialog, and timepickerdialog. In addition, you can inherit Android. App. dialog to implement your own dialog.

2. alertdialog is a dialog box that constructs the default one, two, and three buttons, and one or multiple choice dialog box.

3. progressdialog is derived from alertdialog. In addition to the alertdialog function, progressdialog can display the progress circle or dialog box.

4. datepickerdialog/timepickerdialog is a dialog box that allows users to select a date and a time respectively.

5. Dialog lifecycle callback method: by default, dialog belongs to an activity. The entire lifecycle of the dialog from creation to closure is related to the following callback methods of the activity: oncreatedialog (INT) is called only when the dialog is generated for the first time; onpreparedialog (INT) it is called each time the dialog is displayed. Showdialog (INT) displays dialog; dismissdialog (INT) disables dialog. In addition, you can directly call the dismiss and cancel methods of dialog. When you press the "back" key, the dialog will also be cancel. So when you want to monitor when the dialog is canceled, You can implement the dialoginterface. ondismisslistener interface, and then call the setondismisslistener method to listen.

6. Create alertdialog. Create button dialog box. The syntax for creating a dialog box is as follows: New alertdialog. builder (this ). setmessage (string ). setpositiebutton ("name", new dialoginterface. onclicklistener () {public void onclice ()}). the basic syntax of create (); is to set relevant attributes in the method chain, and pass in the callback method of the button through the internal class.

7. Add list in alertdialog. The syntax is similar to the create button dialog box. New alertdialog. Builder (this). settitle (""). setitems (charsequence [], new dialoginterface. onclicklistener () {public void onclick () {}}). Create.

8. Create a single-choice alertdialog. The syntax is similar to that of the create List dialog box. The difference is that the setitems method is replaced by setsinglechoiceitems ()/setmultichoiceitems.

9. Create progressdialog. Progress bar for creating a circle: progressdialog. Show (context, ""); Create a progress bar: New processdialog (context). setprogressstyle (). setcancelable (). After a progress bar is created, another thread calls dialog. incrementprogressby (INT) to set the progress.

10. Create a custom dialog box. Create a layout in layout. Then you can directly create a new dialog (getapplicationcontext (). setcontentview (R. layout. xx.

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.