android 回调函数使用简介

//1---定义回调函数ide

public interface GirdMenuStateListener {
void onSuccess();
void onError();
}函数


//2---使用的地方声明 和 调用 回调函数 传递结果
public class GirdMenuViewPresenter
{
private GirdMenuStateListener listener;this

public void setListener(GirdMenuStateListener listener) {
this.listener = listener;
}事件


public void loadData(final GirdMenuView gridMenuView) {//自定义方法中使用

if (listener != null)
{
listener.onSuccess();
}
}
}

//3----接收 回调函数结果
public class Presenter extend Activity implements GirdMenuStateListener {回调函数

private GirdMenuStateListener listener;it

private void onCreate()
{

listener=this;

GirdMenuViewPresenter.setListener(listener);
}class

@Override
void onSuccess(){
}
@Override
void onError(){
}cli

}
List

 

 

注意:能够参考系统控件自带的click及相关事件,都是回调函数的写法。grid

相关文章
相关标签/搜索