Event listening in a lib

Asked

Viewed 33 times

1

I’m building a lib but at the end of the process that it performs I need you to let me know that it’s over, how can I implement it? any ideas?

In the project that uses the lib do so:

Lib lib= new Lib (getActivity());      
lib.iniciaInteratividade();

In this initialInterativity() is shown a Dialog and it is done a step by step, in the end wanted to be warned that it ended.

Thank you.

2 answers

2


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 with the interface, declaring it in the class Lib:

public interface OnFinishListener{

    public void onFinish();
}

If you want to pass some information to the "listener" state parameters in the interface method(onFinish())

Declare a method to specify to the class Lib which listener wants to be notified:

//Atributo para guardar o "ouvinte"
private OnFinishListener listener;
public void setOnFinishListener(OnFinishListener listener){
    this.listener = listener;
}

Whenever you want the class Lib 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();
  • Cool, worked right, thanks Ramaral. :D

  • If this is what you were looking for consider accepting the answer by clicking on the V in the upper left corner of it.

  • Had clicked on but not on v , done, thanks again.

0

Fala Marcelo,

You can create a Boolean variable (in Activity), and when you finish the Dialog process you change this variable to true.

Does not solve?

Hugs.

  • Buenas Leonardo, the friend of the above answer solved the problem. Just what I needed was to capture the end of the dialog process (which is inside the lib) so I really needed a Reader. Hugs.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.