创建后修改一个Android对话框的内容 [英] Change the contents of an Android dialog box after creation
问题描述
有一个简单的方法来改变在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()$c$c>方法被称为只是每次对话框
显示的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屋!