0

I have a dialog, which is cancelable, if I click beside of my dialog. But before closing the dialog, I want to check a field and if the check is negative, then the dialog should not close. I thought, that I could do that, if I override the onDismiss() method, but it doesn't work.

Which method I have to override to do the check and decide, if the dialog should close or stay open? Thanks for help :)

twlkyao
  • 14,302
  • 7
  • 27
  • 44
user3621165
  • 212
  • 4
  • 16

2 Answers2

0

To keep dialog open when click the button, you must override the DialogInterface.OnShowListener.
Check the answer Here.
You can use AlertDialog.BUTTON_NEGATIVE to get the negative button, then override the onClickListener yourself to prevent dialog dismissing.

Community
  • 1
  • 1
chartsai
  • 368
  • 3
  • 7
  • I don't have a button in my dialog to close it. I'm using a DialogFragment, which should close, if i click beside of the dialog. So i need to override the method, which is calling dismiss(), if i click beside of my dialog. – user3621165 May 11 '14 at 14:16
  • Oh...sorry, I assumed you use the AlertDialog. orz – chartsai May 11 '14 at 14:23
0

Not sure this is the best solution but you should be able to override the cancel method and call super upon you validation.

@Override
public void cancel() {
    if (YOUR_LOGIC) {
       super.cancel();
    }

    // do nothing
}
JRomero
  • 4,878
  • 1
  • 27
  • 49