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
}
}