I’m creating an android app. I have a Dialog, and I want to handle the onCancel() event without using an anonymous class because it’s cleaner and there are class variables I need access to from the main Activity class. I’m looking for a way to register for events on an object similar to .NET, where I can handle it in a separate method in the class without the need for an anonymous class.
Share
There is a nice example here in the Event Listeners section.
The first example uses an anonymous class for the listener; the second uses a method inside the Activity. No extra class needed.
TL;DR Here is the code stolen from that page:
You can modify this to use
onCancel().