开发框架:MVP

示例代码:

https://github.com/yangzhilong00/testForMVP

功能:有一个“发送验证码”的按钮,点击后连接服务器发送HTTP请求,并显示倒计时。

其实就是分别为M、V、P实现一个接口和一个类,即实现3个接口和3个类

文件目录如下:

 接口初始模板:

public interface IMomentsCommentContract {
    interface View {
        void showMessage(String str);  //显示错误等信息
    }

    interface Presenter{
        void destroy();
    }
}
public interface IMomentsCommentModel {
    interface IMomentsCommentModelAction{
        
    }
}
public class MomentsCommentPresenter implements IMomentsCommentContract.Presenter {
    Context mContext;
    IMomentsCommentContract.View mView;
    MomentsCommentModel mModel;
    Handler mHandler = new Handler();
    
    public MomentsCommentPresenter(Intent intent, Context context, IMomentsCommentContract.View view){
        this.mContext = context;
        this.mView = view;
        mModel = new MomentsCommentModel();
    }
    
    @Override
    public void destroy() {
        //防止内存泄漏
        mHandler.removeCallbacksAndMessages(null);
        mView = null;
    }
}
原文地址:https://www.cnblogs.com/zhaozilongcjiajia/p/11759464.html