- public class MyClass {
- public MyClass(Context context) {
- mContext = context;
- }
- OnLoadFinishedListener onloadfinishedlistener;
- // 提供接口
- public interface OnLoadFinishedListener {
- void onLoadFinish();
- void onLoadFailed();
- }
- public void setOnDataFinishedListener(OnLoadFinishedListener onloadfinishedlistener) {
- this.onloadfinishedlistener = onloadfinishedlistener;
- }
- //将上面代码复制到你的类中,在需要的地方插入加载完毕,或者加载失败的方法即可
- //onloadfinishedlistener.onLoadFinish
- //onloadfinishedlistener.onLoadFailed
- }
调用方法
- //主线程中异步回调方法
- MyClass c =new MyClass(this);
- c.setOnDataFinishedListener(new OnLoadFinishedListener() {
- @Override
- public void onLoadFinish() {
- // 加载完毕
- }
- @Override
- public void onLoadFailed() {
- // 加载失败
- }
- });