开发者

Change the contents of an Android dialog box after creation

Is there a simple way to change the contents of a dialog box in Android without having to re-create the dialog box? I know that Activity.onCreateDialog() is only called once when the dialog first needs to be created, and this is whe开发者_如何学JAVAre you initially set the dialog's contents. I need to change the dialog's contents later, so I'm wondering what is the proper way to do this.


The onPrepareDialog() method is called just before each time the Dialog is displayed allowing you to update it appropriately.

It's passed the same int ID as onCreateDialog() and the Dialog that you created in that method.

@Override
protected void onPrepareDialog(int id, Dialog dialog) {
    //Always call through to super implementation
    super.onPrepareDialog(id, dialog);

    switch (id) {
        case DIALOG_TIME:
            ((AlertDialog)dialog).setMessage("The time is " + new Date());
            break;
    }
}


above did not work for me. calling removeDialog worked without dismissing the AlertDialog

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜