android 4.0 Dialog gets canceled when touched outside of dialog window
Asked Answered
L

3

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.

Lied answered 22/3, 2012 at 19:49 Comment(1)
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.Mosra
C
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.

Cockadoodledoo answered 22/3, 2012 at 20:1 Comment(1)
Default should be false, this caused a lot of problems for my users.Beryl
E
15

You may use

dialog.setCancelable(true/false);

OR

dialog.setCanceledOnTouchOutside(true/false);

For the latest vesrions of Android;

It will disable outSideTouching event.

Exocrine answered 28/11, 2013 at 7:13 Comment(2)
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..Lied
Yes you are right @Lied . So I edited my answer and added a new option setCancelOnTouchOutSide(T/F) event :PExocrine
O
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

Ordinate answered 12/2, 2018 at 4:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.