简体   繁体   中英

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

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.

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM