35

Hi I am facing the problem on ICS like dialog is dismissed when we click outside dialog window, due to which I am getting problem like I don't get any confirmation from user.

Please help.

Sufian Latif
  • 13,086
  • 3
  • 33
  • 70
nishi
  • 1,245
  • 3
  • 13
  • 22
  • 6
    For some reason starting with ICS they made the default `setCanceledOnTouchOutside()` to `true`. The change doesn't seem to be documented anywhere (no surprise). Just clarification for anyone reading. – Tony Chan Sep 13 '12 at 21:13

3 Answers3

66

Check this method from the Android Developers site for dialog.

Try using the

dialog.setCanceledOnTouchOutside (boolean cancel)

Pass a boolean value to enable/disable dialog behaviour when touched outside of the dialog window.

Also go through these links:

How do I fire an event when click occurs outside a dialog

How to cancel an Dialog themed like Activity when touched outside the window?

I hope this answers your question.

Harshawardhan
  • 1,521
  • 1
  • 24
  • 29
15

You may use

dialog.setCancelable(true/false);

OR

dialog.setCanceledOnTouchOutside(true/false);

For the latest vesrions of Android;

It will disable outSideTouching event.

Amt87
  • 5,493
  • 4
  • 32
  • 52
  • 1
    yes we can but that will disable cancellation of dialog on back key press.. many of the times you dont want ur dialog to get cancelled when touched outside but u want to handle the back key press events for dialog.. – nishi Jan 22 '14 at 07:47
  • Yes you are right @nishi . So I edited my answer and added a new option setCancelOnTouchOutSide(T/F) event :P – Amt87 Jan 22 '14 at 10:51
13
dialog.setCancelable(false)

Dialog CAN NOT cancel when touch out side OR press BACK key

dialog.setCanceledOnTouchOutside(false)

Dialog CAN NOT cancel when touched outside BUT ABLE to canceled when press BACK key

Linh
  • 57,942
  • 23
  • 262
  • 279