1

Trying to dynamically change the message of an AlertDialog. For some reason I get a blank dialog box with no message.

@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");
}
}

How can I dynamically change the content of an Alert Dialog?

siamii
  • 23,374
  • 28
  • 93
  • 143
  • explain what you exactly want...? – Siten Mar 22 '11 at 11:04
  • @siten I'd like to change the text of the Alert Dialog each time it is opened. Sometimes it should be "hello world", sometimes "goodbye world". I set the message onPrepareDialog, but I get a blank dialog box.. – siamii Mar 22 '11 at 11:12
  • ok same thing i apply in my app but i take septate dialog method.. n where hello word is use call that method as vice versa... – Siten Mar 22 '11 at 11:24

2 Answers2

3

In onCreateDialog() do aboutDialog.setMessage(""); (or just any other dummy message). If the dialog is missing a message when created, you cannot set it later.

dsnz
  • 415
  • 1
  • 3
  • 10
0

In my own implementation of onPrepareDialog() I'm not calling super.onPrepareDialog. Try removing that line and check the behaviour.

dave.c
  • 10,910
  • 5
  • 39
  • 62