回调函数模型 博客分类: Java编程综合android开发系列Web技术C语言Hibernate技术android
程序员文章站
2024-03-02 18:27:46
...
public class Parent{
.................
...............
private ScrollToScreenCallback scrollToScreenCallback;
interface ScrollToScreenCallback {
public void callback(int currentIndex);
}
public void setScrollToScreenCallback(ScrollToScreenCallback scrollToScreenCallback) {
this.scrollToScreenCallback = scrollToScreenCallback;
}
public void test(){
scrollToScreenCallback.callback(1);
}
}
public class child implements ScrollToScreenCallback {
private Parent parent;
...........
public void callback(int currentIndex){
.......
parent.setScrollToScreenCallback(this);//注意这里要注册回调方法
}
}