mvp基类+retrofit封装 请求数据
来源:互联网 发布:linux gdb调试core文件 编辑:程序博客网 时间:2024/06/11 14:30
//依赖
compile 'com.android.support:recyclerview-v7:26.1.0'compile 'com.jakewharton:butterknife:8.8.1'annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'compile 'com.facebook.fresco:fresco:1.5.0'compile 'com.squareup.retrofit2:retrofit:2.3.0'compile 'com.squareup.retrofit2:converter-scalars:2.3.0'compile 'com.squareup.retrofit2:converter-gson:2.3.0'compile 'com.youth.banner:banner:1.4.10' //最新版本compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'compile 'io.reactivex.rxjava2:rxandroid:2.0.1'compile 'io.reactivex.rxjava2:rxjava:2.1.7'compile 'com.squareup.okhttp3:okhttp:3.9.0'
//view
public interface MyView { public void success(Bean bean); public void failure(Exception e);
}
//回调接口
public interface ModelCallBack { public void success(Bean bean); public void failure(Exception e);}//model
public class MyModel { public void getData(final ModelCallBack callBack){ Map<String,String> map=new HashMap<>();//http://api.svipmovie.com/front/columns/getVideoList.do?catalogId=402834815584e463015584e539330016 map.put("catalogId","402834815584e463015584e539330016"); APIFactory.getInstance().post("front/columns/getVideoList.do", map, new AbstractObserver<Bean>() { @Override public void onSuccess(Bean bean) { callBack.success(bean); } @Override public void onFailure(int code) { callBack.failure(new Exception()); } }); }}
//presenter
public class MyPresenter extends BasePresenter<MyView>{ private MyModel myModel; public MyPresenter() { this.myModel = new MyModel(); } public void getData(){ myModel.getData(new ModelCallBack() { @Override public void success(Bean bean) { view.success(bean); } @Override public void failure(Exception e) { view.failure(e); } }); }}
//mainactivity
public class MainActivity extends BaseMvpActivity<MyView, MyPresenter> implements MyView { @BindView(R.id.recyclerview) RecyclerView recyclerview; private MyAdapter adapter; @Override public MyPresenter initPresenter() { return new MyPresenter(); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); presnter.getData(); recyclerview.setLayoutManager(new LinearLayoutManager(this)); adapter=new MyAdapter(this); recyclerview.setAdapter(adapter); } @Override public void success(Bean bean) { adapter.add(bean); } @Override public void failure(Exception e) { }}
阅读全文
0 0
- mvp基类+retrofit封装 请求数据
- MVP+Retrofit封装网络请求
- MVP和Retrofit+Rxjava+OkHttp封装结合请求数据
- MVP+Retrofit+ReJava+Xrecyclerview请求展示数据
- MVP+Rxjava+Okhttp+Retrofit+XRecyclerview请求数据
- MVP+Rxjava+Retrofit+Fresco网络请求数据
- RxJava+Retrofit+MVP 封装带有加载框的Http请求
- MVp封装RxJava+Retrofit
- MVP +Retrofit +Rxjava 请求
- RxJava结合Retrofit使用 自定义封装类结合泛型 请求网络数据+Fresco+RecyclerView+MVP分层
- MVP模式+OKhttp的封装请求数据
- 简单的MVP+Retrofit+RxJava请求网络数据(一)
- mvp+Retrofit+rxj+greendao的数据请求和增查
- MVP框架使用Retrofit+Rxjava请求网络数据
- MVP+retrofit和Rxjava请求数据+recyclerview展示
- MVP结合RecycleView,利用retrofit与RxJava简单请求数据
- Android Retrofit+RxJava+MVP封装
- retrofit-rxjava封装、mvp-retrofit-rxjava demo
- tensorflow优化
- 菜鸟入门向jdbc与sqlserve2008
- 贪心专练2 最小字典序排序POJ3617
- mysql新增用户
- 华为LTE ME909s模块AT 命令上网流程
- mvp基类+retrofit封装 请求数据
- 异步编程&事件循环event loops---总结
- 数据结构实验之排序六:希尔排序
- svn
- pip更新
- 内连接、左外连接、右外连接、交叉连接区别
- Git 初接触 (三) Git的撤销操作 git commit --amend
- 深入理解java虚拟机学习笔记(三)
- 画图网页http://weavesilk.com/