创建后修改一个Android对话框的内容 [英] Change the contents of an Android dialog box after creation

查看:111
本文介绍了创建后修改一个Android对话框的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个简单的方法来改变在Android中一个对话框的内容,而无需重新创建对话框?我知道,Activity.onCreateDialog()只调用了一次对话首先需要创建时,这是你最初设置对话框的内容。我需要在以后更改对话框的内容,所以我不知道什么是正确的方式做到这一点。

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 where 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.

推荐答案

的<一个href="http://developer.android.com/intl/fr/reference/android/app/Activity.html#on$p$ppareDialog%28int,%20android.app.Dialog%29"><$c$c>on$p$ppareDialog()方法被称为只是每次对话框显示的allowing你更新适当的。

它通过了相同的 INT ID为 onCreateDialog()对话框您在该方法中创建。

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

这篇关于创建后修改一个Android对话框的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆