Android: Daily Learning Notes (8) ——— Explore UI Development (2)

Source: Internet
Author: User

Android: Daily Learning Notes (8) ——— Explore UI Development (2) dialog box Description:

A dialog box is a small window that prompts the user to make a decision or enter additional information. The dialog box does not populate the screen and is typically used for modal events that require the user to take action to continue execution.

Tips: 

  DialogA class is the base class for a dialog box, but you should avoid direct instantiation Dialog and use one of the following subclasses:

    • AlertDialogThis dialog box displays a title, up to three buttons, a list of selectable items, or a custom layout.
    • DatePickerDialogor TimePickerDialog This dialog box has a predefined UI that allows the user to select a date or time.

These classes define the style and structure of your dialog box, but you should use it DialogFragment as a container for dialog boxes .

  The DialogFragment class provides all the controls you need to create a dialog box and manage its appearance, rather than calling Dialog methods on the object .

Description

  Use the DialogFragment Administration dialog box to ensure that it correctly handles life cycle events, such as when a user presses the back button or rotates the screen. In addition, the DialogFragment class allows you to reuse the UI of a dialog box as an embedded component in a larger UI, just as you would in a tradition Fragment (for example, when you want the dialog UI to have a different look and feel on a large screen and a small screen).

a simple way to create a dialog fragment:
Button dialog =(Button) Findviewbyid (R.id.button_dialog); Dialog.setonclicklistener (NewView.onclicklistener () { Public voidOnClick (View v) {Alertdialog.builder dialog=NewAlertdialog.builder (mainactivity. This); Dialog.settitle ( "dialog box title"); Dialog.setmessage ("dialog box to display information"); Dialog.setcancelable (false); Dialog.setpositivebutton ("OK",NewDialoginterface.onclicklistener () { Public voidOnClick (Dialoginterface Dialog,intwhich)                {                    }                }); Dialog.setnegativebutton ("Cancel",NewDialoginterface.onclicklistener () { Public voidOnClick (Dialoginterface Dialog,intwhich)                {                    }                });            Dialog.show (); }        });

Android: Daily Learning Notes (8) ——— Explore UI Development (2)

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.