Android 在警报对话框中显示消息

Android 在警报对话框中显示消息,android,dialog,message,Android,Dialog,Message,尝试动态更改AlertDialog的消息。由于某种原因,我得到一个没有消息的空白对话框 @Override protected Dialog onCreateDialog(int dialogId, Bundle args) { switch (dialogId) { case ABOUT_DIALOG: AlertDialog.Builder aboutDialog = new AlertDialog.Builder(this); return aboutDialog.crea

尝试动态更改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");
}
}

如何动态更改警报对话框的内容?

在我自己实现的
onPrepareDialog()
中,我没有调用
super.onPrepareDialog
。尝试删除该行并检查其行为。

在onCreateDialog()中执行aboutDialog.setMessage(“”);(或任何其他虚拟消息)。
如果对话框在创建时缺少消息,则以后无法设置。

解释您到底想要什么…?@siten每次打开警报对话框时,我都想更改其文本。有时应该是“你好世界”,有时是“再见世界”。我在PrepareDialog上设置了消息,但是我得到了一个空白的对话框。好的,我在我的应用程序中应用了相同的东西,但是我使用septate对话框方法。。在hello word所在的位置,使用调用该方法,反之亦然。。。