Scenario: Use the Pop-up dialog box more than once in an activity. and the dialog box carries dynamically changing information data, assuming that only the oncreatedialog (int ID, bundle bundle) callback is used, then the data that is carried by the first dialog box is not updated. This is because the callback was used only once, and then each time the bundle was used for the first time, the data was not updated.
So you need to work with onpreparedialog (int id, Dialog Dialog, bundle bundle).
Android Alertdialog generate order, call ShowDialog (ID, bundle), first callback oncreatedialog (int ID, bundle bundle). The method is only generated once and then clicked again, it will callback Onpreparedialog (int ID, Dialog Dialog, bundle bundle).
Oncreatedialog (int ID, bundle bundle) Generate dialog box very easy to understand. A different dialog box is generated based on a different ID. See
http://blog.csdn.net/zpf8861/article/details/31423049
No more details here.
In onpreparedialog (int id, Dialog Dialog, bundle bundle), ID is the identity of which dialog box is generated, depending on the ShowDialog (ID, bundle). Bundles are a way to keep the data bundle,bundle with new data as it is kept up to date. Simple data or Object methods are
http://blog.csdn.net/zpf8861/article/details/31730651
Details are not detailed here.
Dialog is the first time a dialog object is called Oncreatedialog returned. The following is a piece of actual code, the key implementation of several places in the removal of bundles, call Setbutton and other methods to implement dialog box related methods and so on.
protected void Onpreparedialog (int id, Dialog Dialog, bundle bundle) {Final Info info = (Info) Bundle.getseriali Zable ("info"); Final Alertdialog Syncdialog = (alertdialog) dialog; Switch (ID) {Case DIALOG_INSTALL:syncDialog.setTitle (getString (R.string.dialog_download_dis, L Abel, size)); Syncdialog.setbutton (Alertdialog.button_positive, getString (r.string.dialog_download), new Onclickl Istener () {@Override public void OnClick (Dialoginterface dialog, in T which) {}}); Syncdialog.setbutton (Alertdialog.button_negative, getString (r.string.dialog_cancel), new Onclicklis Tener () {@Override public void OnClick (dialoginterface dialog, int which) {} }); Break Case DIALOG_UPDATE:syncDialog.setTitle (getString (r.string.dialog_update_dis, label, size)); Syncdialog.setbutton (Alertdialog.button_positive, getString (r.string.dialog_update), new Onclickl Istener () {@Override public void OnClick (Dialoginterface dialog, in T which) {}}); Syncdialog.setbutton (Alertdialog.button_neutral, getString (R.string.dialog_uninstall), new Onclickl Istener () {@Override public void OnClick (Dialoginterface dialog, in T which) {Mlanguagepackupdatemanager.uninstall (info); Syncdialog.dismiss (); } }); SyncDIalog.setbutton (Alertdialog.button_negative, getString (r.string.dialog_cancel), new Onclicklistener () {@Override public void OnClick (Dialoginterface dialog, int which ) { } }); Break Case DIALOG_UNINSTALL:syncDialog.setTitle (getString (r.string.dialog_uninstall_dis, label, size)); Syncdialog.setbutton (Alertdialog.button_positive, getString (R.string.dialog_uninstall), new Onclicklistener () {@Override public void OnClick (Dialoginterface D Ialog, int which) {}}); Syncdialog.setbutton (Alertdialog.button_negative, getString (r.string.dialog_cancel), new Onclickl Istener () {@Override public void OnClick (Dialoginterface dialog, int which) {} }); Break Default:break; } }
Oncreatedialog and Onpreparedialog usage of Alertdialog