I try to create AlertDialog. It works but setMessage doesn't refresh message. Code snippet below:
@Override
protected Dialog onCreateDialog(int id) {
super.onCreateDialog(id);
switch (id) {
case CONFIRM:
confirmView = new LinearLayout(this);
return new AlertDialog.Builder(this)
.setIcon(android.R.drawable.ic_dialog_info)
.setView(confirmView)
.setCancelable(false)
.setTitle("The WiFi")
.setMessage(infoMsg);
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Functionality.StartWiFiManager(ControllerService.this);
}
})
.setNegativeButton("Cancel", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.create();
}
}
Invoking:
infoMsg = "My message";
showDialog(CONFIRM);
So when I change my infoMsg and invoke showDialog again, the message is the same. What am I doing wrong? Please, help me.
You need to use 'onPrepareDialog' to reset information that changes every time the dialog is shown. onCreateDialog is only called once, then the dialog is held onto and re-used. onPrepareDialog is called every time that the dialog is shown.
Of course, both onCreateDialog and onPrepareDialog are deprecated and you are supposed to be using 'DialogFragment' class and the 'FragmentManager' instead. But if you (like me) are continuing to use the old APIs, then onPrepareDialog is what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With