How to catch a touch event of a dialog box when clicking on it outside

Actually, I have Dialogin my activity, I want the dialog box to be open, then in the “Touch an external screen” dialog box I want to reject the dialog, and at the same time I want to call a function that does some updating in my activity .

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

So what will be the best solution for this. Please help me solve this problem.

+5
source share
1 answer

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

How to cancel a dialog, for example, "Activity" when it is touched outside the window?

+2
source

All Articles