【发布时间】:2011-03-22 11:02:00
【问题描述】:
尝试动态更改 AlertDialog 的消息。出于某种原因,我得到一个没有任何消息的空白对话框。
@Override
protected Dialog onCreateDialog(int dialogId, Bundle args) {
switch (dialogId) {
case ABOUT_DIALOG:
AlertDialog.Builder aboutDialog = new AlertDialog.Builder(this);
return aboutDialog.create();
}
}
@Override
protected void onPrepareDialog(int dialogId, Dialog dialog, Bundle args){
super.onPrepareDialog(dialogId, dialog, args);
switch(dialogId){
case ABOUT_DIALOG:
AlertDialog aboutDialog = (AlertDialog) dialog;
aboutDialog.setMessage("hello world");
}
}
如何动态更改警报对话框的内容?
【问题讨论】:
-
解释一下你到底想要什么...?
-
@siten 我想在每次打开警报对话框时更改它的文本。有时应该是“hello world”,有时应该是“goodbye world”。我在PrepareDialog上设置了消息,但我得到一个空白对话框..
-
好的,我在我的应用程序中应用了同样的东西,但我采用了分隔对话框方法.. n 使用你好词的地方调用该方法,反之亦然......