回调

主函数:

public
class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_main); B b = new B(); b.bMothed(); } }

接口:

public interface Callback {
    void print(String s);
}

Class A

public class A {
    public void mothed(Callback callback) {
       callback.print("callback A");
    }
}

Class B

public class B implements Callback{

    public void bMothed() {
        A a = new A();
        a.mothed(this);
    }

    @Override
    public void print(String s) {
        Log.e("i am B",s);
    }
}

 

posted @ 2016-05-09 16:44  Pepper.B  阅读(158)  评论(0编辑  收藏  举报