In my app, I’m using an AlertDialog with a custom view. This view contains a couple of EditTexts and a few other things. There are some listeners attached to the EditTexts that perform whatever functionality is needed.
On the button click of the dialog, I am performing some validation on the data entered into the EditTexts and display another AlertDialog if the data is invalid. Once that (second) dialog is closed, I want to remain on the main dialog (with the custom view), but for some reason that dialog is closed before my second dialog is shown. How can I keep the original (custom view) dialog still open under the second dialog?
Here’s my (simplified) code:
final EntryPanel panel = new EntryPanel(OrderActivity.this);
AlertDialog dlg = new AlertDialog.Builder(OrderActivity.this)
.setCancelable(true)
.setView(panel)
.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final int id = pePanel.getProductId();
if(!isValidProduct(id)) {
new AlertDialog.Builder(OrderActivity.this)
.setMessage(R.string.error_unknown_product)
.setCancelable(true)
.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dlg2, int which) {
dlg2.cancel();
}
})
.show();
}
else {
processProductEntry(id);
dialog.dismiss();
}
}
})
.setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
}).show();
So, it’s not possible to keep both dialogs open. Therefore I changed the first dialog (with the custom view) to be an activity with
themebeingTheme.Dialog– it displays the way it should – and then open the second dialog from it. This way, when the second dialog is opened, the original activity (which looks like a dialog) is still visible in the background.