7

I have Dialog in my activity, what I want is suppose the dialog is open, then on Touch of outside dialog I want to dismiss the dialog, and at the same time, I want to call a function which does some update in my activity.

Initially I used MyDialog.setCanceledOnTouchOutside(true); But these will only dismiss and in my case, at the same time I want to call some functions whenever user click outside of a dialog. So what should I do? I know that if I can extend the Dialog class and override its onTouchEvent method then it will be solved but in my case, my class already extends Activity class and in java, we can't extend more then one class.

So what will be the best solution for that? Please help me to solve this out.

iknow
  • 8,358
  • 12
  • 41
  • 68
AndroidDev
  • 4,521
  • 24
  • 78
  • 126
  • This link seems similar to what you want to achieve. [link][1] [1]: http://stackoverflow.com/questions/5185517/updating-android-edittexts-hint-on-focus-change-using-xml-only – geekoraul May 22 '12 at 06:25
  • @geekoraul I dont think that u read my question....... – AndroidDev May 22 '12 at 06:27
  • @AndroidCoder : MyDialog.setCanceledOnTouchOutside(false) help me to restrict cancel of dialog, but in this case focus form dialog button also lost...any idea how can retain focus on dialog button eve click outside. – CoDe May 27 '13 at 11:36

1 Answers1

2

The second answer on this thread shows how to do this (used it myself, works):

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

Community
  • 1
  • 1
Tony
  • 2,335
  • 21
  • 25
  • This code is used to finish an activity..but in my case i want to dismiss a dilog – AndroidDev May 22 '12 at 06:39
  • I see, sorry. Can you use the same logic though? If you set MyDialog.setCanceledOnTouchOutside(false); then catch the touch outside and dismiss the dialog programatically? – Tony May 22 '12 at 06:41
  • can u show me with an example code............if possible..what function should catch the touch outside...... – AndroidDev May 22 '12 at 06:42
  • Not for that but looking at it their is a OnCancelListener for dialog. Some example code here: http://stackoverflow.com/questions/2195497/problem-using-progressdialog-with-oncreatedialog-onpreparedialog Might help – Tony May 22 '12 at 06:50
  • Its not what the question is about but in the question's code block inside OnPrepareDialog, there is a onCancelListener.. inside I think you would add the code you want to execute once the dialog cancels – Tony May 22 '12 at 06:55
  • Yeh things get work..what i have to do is first set setCanceledOnTouchOutside(true); then call setOnCancelListener...thanks buddy.......... – AndroidDev May 22 '12 at 07:00