Oncreatedialog and Onpreparedialog usage of Alertdialog

Source: Internet
Author: User

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

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.