I have created a Class named NumericPicker, which is created in a Dialog. But it can be used in any Activity so I don’t want to use any type of Object or Dataset in the Class.
The problem is I need to have in the Activity a way to know when the Dialog is closed so I could save the values I need (like startActivityForResult()). I think I could extend the Class to Activity and set the Theme to Dialog, but that’s not the idea, the Class should not extend Activity.
Any suggestion to do this?
Implement your own listener/callback. For example, create an onCloseListener interface. Your activity will implement the interface, and the dialog implements a
setOnCloseListenermethod. When creating the dialog, you assign the activity as the onCloseListener, and when the dialog is closing, it calls the interface method implemented in your activity.Here’s an example of a listener interface and implementation declared inside of a custom view called DrawView:
This is an activity’s implementation declaration and setting the listener:
Invoking the callback in DrawView: