Android 回调机制

1,定义回调接口

public interface SlotCard {
    void onSlotListener(String carid);
}

 

2,定义类A

public class A{

 public static SlotCard slotCardlistener;

slotCardlistener.onSlotListener(card);

public static void setOnSlotCardListenre(SlotCard listener){
    slotCardlistener = listener;
}

}

3.定义类B

public class B implements SlotCard{

A.setOnSlotCardListenre(this);

@Override
public void onSlotListener(String carid) {
    Log.d("888888888888888","carid = "+carid);
}

}

你可能感兴趣的:(java)