How to dynamically change the dialog box value in Android

Source: Internet
Author: User

The usage is as follows: Activity. showDialog () inspires Activity. onCreateDialog () to create a Dialog and display it to facilitate unified management of multiple Dialog.

Note: When Activity. showDialog () is used to display the same Dialog, Activity. onCreateDialog () is not called (),

Instead, Activity. onPrepareDialog () is called to display the status of the last Dialog. That is

First time: showDialog ()-> onCreatedialog ()
Later: showDialog ()-> onPrepareDialog ()

When you use the oncreatedigd callback to create a dialogd, the system caches the dialog and displays the last displayed content next time.

When a Dialog is called for the first time, the Android system will call the onCreateDialog method of the Activity that you want to instantiate Dialog,

This method will start the Dialog defined by the ID parameter passed from the showDialog (int) method. After you create successfully, return the Dialog at the end of the method.

Before the Dialog display, Android also calls the callback function onPripareDialog (int, Dialog). You can define this method when you want to change some attributes of this Dialog each time you open it,

This method is called every time the Dialog is opened. onCreateDialog () is called only when the Dialog is opened for the first time. If onPrepareDialog () is not defined (),

The returned Dialog is the same as the displayed Dialog for the first time. This method must pass an ID and the Dialog created in the onCreateDialog () method.

It is best to define onCreateDialog () and onPrepareDialog () to use switch to determine the input id. Each case corresponds to the ID of the Dialog to be started.

Copy codeThe Code is as follows: * dynamically change the dialog box Value
* Key point: Call removeDialog (id) in the onPrepareDialog method );
* Dialog box call execution sequence showDialog ()-> onCreateDialog ()-> onPrepareDialog ()-> removeDialog ()

@ Override
Public void onPrepareDialog (int id, Dialog dialog ){
Switch (id ){
Case (DIALOG_SORT_MAILS ):
RemoveDialog (id); // remove the Dialog created by onCreateDialog ()
Break;
}
}

Related Article

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.