I do a check and play 3 dialogs on the screen, however if the user cancels one of them, everyone should close. Does anyone know how to do this? I do not even know if it's possible. Thank you in advance.
I do a check and play 3 dialogs on the screen, however if the user cancels one of them, everyone should close. Does anyone know how to do this? I do not even know if it's possible. Thank you in advance.
Of course it is possible, if you have a reference to the three created dialogs, you simply intercept the click on one of them and do something like:
dialog1.dismiss();
dialog2.dismiss();
dialog3.dismiss();
Well, a complete example would look like this:
AlertDialog.Builder builder1 = new AlertDialog.Builder(this);
builder1.setMessage("Exemplo");
builder1.setPositiveButton("Sim", null);
builder1.setNegativeButton("Não", null);
final AlertDialog dialog1 = builder1.show();
AlertDialog.Builder builder2 = new AlertDialog.Builder(this);
builder2.setMessage("Exemplo");
builder2.setPositiveButton("Sim", null);
builder2.setNegativeButton("Não", null);
final AlertDialog dialog2 = builder2.show();
AlertDialog.Builder builder3 = new AlertDialog.Builder(this);
builder3.setMessage("Exemplo");
builder3.setPositiveButton("Sim", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog3, int i) {
dialog3.dismiss();
dialog1.dismiss();
dialog2.dismiss();
}
});
builder3.setNegativeButton("Não", null);
AlertDialog dialog3 = builder3.show();
By clicking on the dialog3
, all three dialogs will be closed.