How to dynamically Change dialog box values in Android _android

Source: Internet
Author: User

Using this method, Activity.showdialog () fires Activity.oncreatedialog () to create dialog, which is then displayed to facilitate the unified management of multiple dialog.

Note that Activity.oncreatedialog () is not invoked when the same dialog is displayed later with Activity.showdialog ().

Instead, call Activity.onpreparedialog () to use the state of the last time the dialog was displayed. That

First time: ShowDialog ()-> Oncreatedialog ()
later: ShowDialog ()-> Onpreparedialog ()

When you create a dialogd with a Oncreatedialog callback, the system caches the dialog and displays the last displayed content the next time.

When a dialog is invoked for the first time, the Android system invokes the Oncreatedialog method that you should instantiate the dialog activity.

This method initiates the dialog defined by the ID parameter that you pass from the ShowDialog (int) method, and when you create the success, return the dialog at the end of the method.

Android also invokes the callback function Onpriparedialog (Int,dialog) before the Dialog is displayed, and you can define this method when you want some properties to be changed at each time the Dialog is opened.

This method is invoked every time the dialog is opened, and Oncreatedialog () is invoked only when dialog is first opened, if you do not define Onpreparedialog (),

Each time the returned dialog is the same as the first displayed dialog, this method needs to pass an ID and the dialog created in the Oncreatedialog () method.

The best definition Oncreatedialog () and Onpreparedialog () uses the switch to judge the incoming ID, each case corresponding to the ID of the dialog to be started

Copy Code code as follows:

* Dynamically changing dialog box values
* Key point: Onpreparedialog method inside the call Removedialog (ID);
* dialog box Call execution Order 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.