Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to catch touch event of a dialog when it is clicked outside

Tags:

android

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.

like image 536
AndroidDev Avatar asked May 22 '12 06:05

AndroidDev


1 Answers

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?

like image 155
Tony Avatar answered Nov 12 '22 08:11

Tony