Dialog open twice on fast click of button
You have to just check whether your Dialog
is already shown or not:
Dialog passwordDialog = new Dialog(SettingsActivity.this);
holder.butDelete.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(!passwordDialog.isShowing()) {
passwordDialog.show();
}
}
});
Update:
If this doesn't work in your case, then in your activity declare globally:
Dialog passwordDialog = null;
and on Button
's click:
holder.butDelete.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(passwordDialog == null) {
passwordDialog = new Dialog(SettingsActivity.this);
passwordDialog.show();
}
}
});
Declared globally:
private Boolean dialogShownOnce = false;
private mDialog dia;
Where your dialog.show();
is called:
dia = new mDialog(getContext());
if (!dia.isShowing() && !dialogShownOnce) {
dia.show();
dialogShownOnce = true;
}
dia.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
dialogShownOnce = false;
}
});
mDialog does not have to be global, but I was calling mDialog.dismiss()
in some out-of-local-scope interfaces.
Still uses a Boolean
, but I don´t understand why it can´t be used.