Reputation: 61
I want to show a dialog. When click outside the dialog , i want dialog to get dismiss. But before dismissing a dialog, i want to check for a condition, if correct then dismiss the dialog, else if value is incorrect don't dismiss it.
Can anyone help me? Thank you.
Upvotes: 0
Views: 898
Reputation: 326
You can check the value when inputting with TextWatcher
. Or set custom onClickListener to the positive button.
AlertDialog.Builder builder = new AlertDialog.Builder();
// build dialog
AlertDialog dialog = builder.create();
dialog.setOnShowListener(new DialogInterface.OnShowListener(){
@Override
public void onShow(DialogInterface dialogInterface){
((AlertDialog)dialogInterface).getButton(AlertDialog.BUTTON_POSITIVE)
.setOnClickListener(// check value here)
}
}
dialog.show();
remember to invoke dialogInterface.dismiss()
when you ready to dismiss it.
Upvotes: 0
Reputation: 17580
Keep setCancelabe(false);
until the value in the EditText
is not correct. use TextWatcher
to check value, and whenever your value is correct then set setCancelabe(true);
Upvotes: 1