Reputation: 24094
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?
Upvotes: 1
Views: 4025
Reputation: 415
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.
Upvotes: 3
Reputation: 10908
In my own implementation of onPrepareDialog()
I'm not calling super.onPrepareDialog
. Try removing that line and check the behaviour.
Upvotes: 0