I. 定义接口B, A implements B
public interface B {
public void onResult();
}
public class A implements B {
public void onResult() {
//execute method();
}
}
II. 定义类B, B中封装接口, A implements B
public class B {
public interface InterfaceB {
public void onResult(int para1, int para2, object para3); //类里定义接口和回调方法
}
private ArrayList<InterfaceB> listeners = new ArrayList<~>(); //类里定义接口调用者
public void registerListener(InterfaceB l) {
listeners.add(l);
}
public void unregisterListener(InterfaceB l) {
listeners.remove(l);
}
}
public class A implements B {
B.getInstance().regsiterListener(this); //向接口调用者队列里add一个接口调用者: this
public void onResult(int para1, int para2, object para3) {
//execute method();
}
}