You create an interface first, then implement a method, where you set the listener in your custom class and already then make a main class to listen for your custom event
Interface:
public interface OnCustomEventListener{
public void onEvent(); //can have parameters
}
method in your e.g. adapter: private OnCustomEventListener mListener; //field
//setter method
public void setCustomEventListener(OnCustomEventListener eventListener) {
this.mListener=eventListener;
}
listener:
someObjectYouWantToHaveYourCustomListenerToBeAssignedFor.setCustomEventListener(new OnCustomEventListener(){
public void onEvent(){
//do whatever you want to do when the event is performed.
}
});
how to call e.g. from your adapter:
if(this.mListener!=null){
this.mListener.onEvent();
}
P.S. Your custom listener may have as many parameters as you want