0

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.

Meenal
  • 2,879
  • 5
  • 19
  • 43
Thị Duyên
  • 61
  • 1
  • 6

2 Answers2

1

Keep setCancelabe(false); until the value in the EditText is not correct. use TextWatcherto check value, and whenever your value is correct then set setCancelabe(true);

T_V
  • 17,440
  • 6
  • 36
  • 48
0

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.

Tomaz Wang
  • 316
  • 4
  • 11