First you create an interface, and then you define a method that will act as a callback. In this example, we would have two classes: one classA and another classB
Interface:
public interface OnCustomEventListener{ public void onEvent();
the listener in class B (we install only the listener in class B)
private OnCustomEventListener mListener;
in class A, how do we start listening to what class B should say
classB.setCustomEventListener(new OnCustomEventListener(){ public void onEvent(){
how do we fire an event from class B (for example, clicking a button)
if(this.mListener!=null){ this.mListener.onEvent(); }
PS Your custom listener can have as many parameters as you want.
Source
Mocialov Boris Aug 05 '13 at 9:30 a.m. 2013-08-05 09:30
source share