If you want to listen to an event, then create one.
A simple way to do this is to define an interface that the "listener" object must implement to be notified when the event occurs.
Start the interface by declaring it in the Lib class:
public interface OnFinishListener{
public void onFinish();
}
If you want to pass some information to the listener, declare parameters in the interface method ( onFinish()
)
Declare a method to tell the Lib class which listener wants to be notified:
//Atributo para guardar o "ouvinte"
private OnFinishListener listener;
public void setOnFinishListener(OnFinishListener listener){
this.listener = listener;
}
When you want the Lib class to notify the "listener" use:
if(listener != null){
listener.onFinish();
}
To use do so:
Lib lib = new Lib (getActivity());
lib.setOnFinishListener(new OnFinishListener(){
@Override
public void onFinish(){
//Coloque aqui o código a ser executado quando receber a notificação.
}
});
lib.iniciaInteratividade();