实现思路必须步骤。新框架愿各位同门进行学习,思路清析一下。

一,首先添加依赖。

compile 'com.squareup.retrofit2:converter-gson:2.3.0'

implementation 'com.android.support:recyclerview-v7:26.1.0'
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'org.greenrobot:greendao:3.2.0'
compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
compile 'org.greenrobot:eventbus:3.1.1'
compile 'com.facebook.fresco:fresco:1.5.0'

二。添加网络权限;

  <uses-permission android:name="android.permission.INTERNET"/>

三。接下来就是类的创建。

1,对对数据类的封装。创建bean类。

public class Bean {/**
     * code : 200
     * msg : success
     * data : {"category":[{"id":"16","cat_name":"按功效","is_leaf":"0","children":[{"id":"17","cat_name":"补水保湿","is_leaf":"1"},{"id":"31","cat_name":"舒缓修护","is_leaf":"1"},{"id":"19","cat_name":"控油去痘","is_leaf":"1"},{"id":"18","cat_name":"美白提亮","is_leaf":"1"},{"id":"20","cat_name":"紧致抗皱","is_leaf":"1"}]},{"id":"6","cat_name":"按属性","is_leaf":"0","children":[{"id":"38","cat_name":"面膜","is_leaf":"0"},{"id":"39","cat_name":"润肤水","is_leaf":"1"},{"id":"40","cat_name":"润肤乳","is_leaf":"1"},{"id":"24","cat_name":"洁面乳","is_leaf":"0"},{"id":"35","cat_name":"其他","is_leaf":"0"},{"id":"33","cat_name":"实惠套装","is_leaf":"1"},{"id":"9","cat_name":"贴式面膜","is_leaf":"0"},{"id":"10","cat_name":"睡眠面膜","is_leaf":"0"},{"id":"23","cat_name":"泥浆面膜","is_leaf":"0"},{"id":"41","cat_name":"男士","is_leaf":"0"}]},{"id":"11","cat_name":"按肤质","is_leaf":"0","children":[{"id":"14","cat_name":"混合性肤质","is_leaf":"1"},{"id":"13","cat_name":"中性肤质","is_leaf":"1"},{"id":"29","cat_name":"干性肤质","is_leaf":"1"},{"id":"28","cat_name":"油性肤质","is_leaf":"1"},{"id":"15","cat_name":"痘痘肤质","is_leaf":"1"},{"id":"37","cat_name":"敏感肤质","is_leaf":"0"}]}],"goodsBrief":[{"id":"121","goods_name":"经典款丨美白嫩肤面膜7片","shop_price":49.9,"market_price":99,"goods_img":"https://image.yunifang.com/yunifang/images/goods/121/goods_img/17062610568378169043195978.jpg","reservable":false,"efficacy":"美白嫩肤 层层葆鲜","stock_number":0,"restrict_purchase_num":0},{"id":"684","goods_name":"解救肌渴丨花粹水润面膜套装10片","shop_price":29.9,"market_price":139,"goods_img":"https://image.yunifang.com/yunifang/images/goods/684/goods_img/17062610401397749701177609.jpg","reservable":false,"efficacy":"水润充盈 鲜嫩少女肌","stock_number":0,"restrict_purchase_num":0},{"id":"772","goods_name":"热销爆款丨清润莹亮黑膜套装21片","shop_price":99.9,"market_price":297,"goods_img":"https://image.yunifang.com/yunifang/images/goods/772/goods_img/171016095389114258195255761.jpg","reservable":false,"efficacy":"自然莹亮  水感瓷肌","stock_number":0,"restrict_purchase_num":0},{"id":"5","goods_name":"亮采金桂花眼膜贴60片","shop_price":69,"market_price":129,"goods_img":"https://image.yunifang.com/yunifang/images/goods/5/goods_img/17103118031591202108007689.jpg","reservable":false,"efficacy":"补水靓眼 改善熊猫眼","stock_number":0,"restrict_purchase_num":0},{"id":"343","goods_name":"美白嫩肤润肤水150ml","shop_price":69,"market_price":119,"goods_img":"https://image.yunifang.com/yunifang/images/goods/343/goods_img/170626103423611420000294568.jpg","reservable":false,"efficacy":"补水保湿 美白嫩肤","stock_number":0,"restrict_purchase_num":0},{"id":"9","goods_name":"玫瑰滋养矿物睡眠面膜180g","shop_price":59.9,"market_price":99,"goods_img":"https://image.yunifang.com/yunifang/images/goods/9/goods_img/170626112611018894167156705.jpg","reservable":false,"efficacy":"镇店之宝 彻夜补水","stock_number":0,"restrict_purchase_num":0},{"id":"10","goods_name":"美白嫩肤睡眠面膜180g","shop_price":69,"market_price":119,"goods_img":"https://image.yunifang.com/yunifang/images/goods/10/goods_img/170626112190919312919673075.jpg","reservable":false,"efficacy":"水润一夜 美白透亮","stock_number":0,"restrict_purchase_num":0},{"id":"446","goods_name":"芦荟补水保湿凝胶150g","shop_price":49.9,"market_price":89,"goods_img":"https://image.yunifang.com/yunifang/images/goods/446/goods_img/17112211433972519259384989.jpg","reservable":false,"efficacy":"滋养肌肤 自然水润","stock_number":0,"restrict_purchase_num":0},{"id":"16","goods_name":"玫瑰滋养保湿四件套","shop_price":169.9,"market_price":259.9,"goods_img":"https://image.yunifang.com/yunifang/images/goods/16/goods_img/17062611152592656236701367.jpg","reservable":false,"efficacy":"一整套源源补水","stock_number":0,"restrict_purchase_num":0},{"id":"8","goods_name":"全新升级丨美白嫩肤面膜20片","shop_price":129.9,"market_price":359,"goods_img":"https://image.yunifang.com/yunifang/images/goods/8/goods_img/170818182578717903477668239.jpg","reservable":false,"efficacy":"真美白 匠心造","stock_number":0,"restrict_purchase_num":0},{"id":"14","goods_name":"矿物泥浆鼻膜60g","shop_price":55,"market_price":69,"goods_img":"https://image.yunifang.com/yunifang/images/goods/14/goods_img/170626111762918631255244111.jpg","reservable":false,"efficacy":"收敛毛孔 改善黑头","stock_number":0,"restrict_purchase_num":0},{"id":"189","goods_name":"清爽平衡护肤三件套","shop_price":99.9,"market_price":179.9,"goods_img":"https://image.yunifang.com/yunifang/images/goods/189/goods_img/1706261046499486999388441.jpg","reservable":false,"efficacy":"深层清洁 平衡水油","stock_number":0,"restrict_purchase_num":0},{"id":"11","goods_name":"清爽平衡矿物泥浆面膜260g","shop_price":99,"market_price":99,"goods_img":"https://image.yunifang.com/yunifang/images/goods/11/goods_img/170626112085420599974158029.jpg","reservable":false,"efficacy":"口碑泥浆 清爽控油","stock_number":0,"restrict_purchase_num":0},{"id":"4","goods_name":"黑玫瑰矿物洁面乳100ml","shop_price":49,"market_price":59,"goods_img":"https://image.yunifang.com/yunifang/images/goods/4/goods_img/17062611262464209534577694.jpg","reservable":false,"efficacy":"温和清洁 提亮肤色","stock_number":0,"restrict_purchase_num":0},{"id":"559","goods_name":"竹炭净透矿物泥浆面膜110g","shop_price":59,"market_price":99,"goods_img":"https://image.yunifang.com/yunifang/images/goods/559/goods_img/170627164784010618075663103.jpg","reservable":false,"efficacy":"控油净肤 细腻毛孔","stock_number":0,"restrict_purchase_num":0}]}
     */

    private int code;private String msg;private DataBean data;public int getCode() {return code;}public void setCode(int code) {this.code = code;}public String getMsg() {return msg;}public void setMsg(String msg) {this.msg = msg;}public DataBean getData() {return data;}public void setData(DataBean data) {this.data = data;}public static class DataBean {private List<CategoryBean> category;private List<GoodsBriefBean> goodsBrief;public List<CategoryBean> getCategory() {return category;}public void setCategory(List<CategoryBean> category) {this.category = category;}public List<GoodsBriefBean> getGoodsBrief() {return goodsBrief;}public void setGoodsBrief(List<GoodsBriefBean> goodsBrief) {this.goodsBrief = goodsBrief;}public static class CategoryBean {/**
             * id : 16
             * cat_name : 按功效
             * is_leaf : 0
             * children : [{"id":"17","cat_name":"补水保湿","is_leaf":"1"},{"id":"31","cat_name":"舒缓修护","is_leaf":"1"},{"id":"19","cat_name":"控油去痘","is_leaf":"1"},{"id":"18","cat_name":"美白提亮","is_leaf":"1"},{"id":"20","cat_name":"紧致抗皱","is_leaf":"1"}]
             */

            private String id;private String cat_name;private String is_leaf;private List<ChildrenBean> children;public String getId() {return id;}public void setId(String id) {this.id = id;}public String getCat_name() {return cat_name;}public void setCat_name(String cat_name) {this.cat_name = cat_name;}public String getIs_leaf() {return is_leaf;}public void setIs_leaf(String is_leaf) {this.is_leaf = is_leaf;}public List<ChildrenBean> getChildren() {return children;}public void setChildren(List<ChildrenBean> children) {this.children = children;}public static class ChildrenBean {/**
                 * id : 17
                 * cat_name : 补水保湿
                 * is_leaf : 1
                 */

                private String id;private String cat_name;private String is_leaf;public String getId() {return id;}public void setId(String id) {this.id = id;}public String getCat_name() {return cat_name;}public void setCat_name(String cat_name) {this.cat_name = cat_name;}public String getIs_leaf() {return is_leaf;}public void setIs_leaf(String is_leaf) {this.is_leaf = is_leaf;}}}}
}
2.创建连接bean—— GoodsBriefBean 类。
public  class GoodsBriefBean {/**
     * id : 121
     * goods_name : 经典款丨美白嫩肤面膜7片
     * shop_price : 49.9
     * market_price : 99.0
     * goods_img : https://image.yunifang.com/yunifang/images/goods/121/goods_img/17062610568378169043195978.jpg
     * reservable : false
     * efficacy : 美白嫩肤 层层葆鲜
     * stock_number : 0
     * restrict_purchase_num : 0
     */
    @Id(autoincrement = true)private Long iid;private String id;private String goods_name;private double shop_price;private double market_price;private String goods_img;private boolean reservable;private String efficacy;private int stock_number;private int restrict_purchase_num;public GoodsBriefBean() {}public String getId() {return id;}public void setId(String id) {this.id = id;}public String getGoods_name() {return goods_name;}public void setGoods_name(String goods_name) {this.goods_name = goods_name;}public double getShop_price() {return shop_price;}public void setShop_price(double shop_price) {this.shop_price = shop_price;}public double getMarket_price() {return market_price;}public void setMarket_price(double market_price) {this.market_price = market_price;}public String getGoods_img() {return goods_img;}public void setGoods_img(String goods_img) {this.goods_img = goods_img;}public boolean isReservable() {return reservable;}public void setReservable(boolean reservable) {this.reservable = reservable;}public String getEfficacy() {return efficacy;}public void setEfficacy(String efficacy) {this.efficacy = efficacy;}public int getStock_number() {return stock_number;}public void setStock_number(int stock_number) {this.stock_number = stock_number;}public int getRestrict_purchase_num() {return restrict_purchase_num;}public void setRestrict_purchase_num(int restrict_purchase_num) {this.restrict_purchase_num = restrict_purchase_num;}public Long getIid() {return this.iid;}public void setIid(Long iid) {this.iid = iid;}public boolean getReservable() {return this.reservable;}
}

3.创建参数Bean。

public class EventBean {public String url;public String title;public EventBean(String url, String title) {this.url = url;this.title = title;}public String getUrl() {return url;}public String getTitle() {return title;}
}

4, IApplication初始化类的创建。

public class IApplication extends Application {public static IGetDataBase iGetDataBase;public static DaoSession session;@Override
    public void onCreate() {super.onCreate();Fresco.initialize(this);Retrofit retrofit = new Retrofit.Builder().baseUrl("http://m.yunifang.com").addConverterFactory(GsonConverterFactory.create()).build();iGetDataBase = retrofit.create(IGetDataBase.class);DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this,"test1");Database database =  helper.getWritableDb();session = new DaoMaster(database).newSession();}
}

三,实现Model包中的类。

1,第一步创建MainModel接口·

    public interface MainModel {}

2,创建 MainModelImpl类。

public class MainModelImpl {/**
     * get 请求
     * @param callBack
     */
    public void getData(final ModelCallBack callBack){Call<Bean> call = IApplication.iGetDataBase.get("96333","bf3386e14fe5bb0bcef234baebca2414");call.enqueue(new Callback<Bean>() {@Override
           public void onResponse(Call<Bean> call, Response<Bean> response) {Bean bean = response.body();callBack.onSuccess(bean);IApplication.session.getGoodsBriefBeanDao().insertInTx(bean.getData().getGoodsBrief());}@Override
           public void onFailure(Call<Bean> call, Throwable t) {callBack.onFailure(new Exception(""));}});}/**
     * post 请求
     */
    public void  postData(final ModelCallBack callBack){Call<Bean> call = IApplication.iGetDataBase.get("96333","bf3386e14fe5bb0bcef234baebca2414");call.enqueue(new Callback<Bean>() {@Override

            public void onResponse(Call<Bean> call, Response<Bean> response) {Bean bean = response.body();callBack.onSuccess(bean);}@Override
            public void onFailure(Call<Bean> call, Throwable t) {callBack.onFailure(new Exception("") );}});}
}

3, 创建ModelCallBack接口。

public interface ModelCallBack {public void onSuccess(Bean bean);public void onFailure(Exception e);}

四。实现presenter包中的类。

    1,创建MainPresenter类。
public class MainPresenter {private IMainView iView ;private MainModelImpl mainModel ;public MainPresenter(IMainView view){this.iView = view;this.mainModel = new MainModelImpl();}public void get(){mainModel.getData(new ModelCallBack() {@Override
            public void onSuccess(Bean bean) {if(iView != null){iView.onSuccess(bean);}}@Override
            public void onFailure(Exception e) {if(iView != null){iView.onFailure(e);}}});}public void post(){mainModel.postData(new ModelCallBack() {@Override
            public void onSuccess(Bean bean) {if(iView != null){iView.onSuccess(bean);}}@Override
            public void onFailure(Exception e) {if(iView != null){iView.onFailure(e);}}});}}

五。实现view包中类。

1,创建IMainView类。

public interface IMainView {public void onSuccess(Bean bean);public void onFailure(Exception e);
}

六。创建adapter得类。

创建IApdater适配器类。

public class IApdater extends RecyclerView.Adapter<IApdater.IViewHolder>{Context context;List<GoodsBriefBean> list ;public IApdater(Context context) {this.context = context;}public void addData(Bean bean){if(list == null){list = new ArrayList<>();}list.addAll(bean.getData().getGoodsBrief());notifyDataSetChanged();}@Override
    public IApdater.IViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {View view = View.inflate(context, R.layout.layout, null);return new IViewHolder(view);}@Override
    public void onBindViewHolder(IApdater.IViewHolder holder, final int position) {//holder.adapterSimpledraweeview.setImageURI("https://image.yunifang.com/yunifang/images/goods/121/goods_img/17062610568378169043195978.jpg");
        holder.adapterSimpledraweeview.setImageURI(list.get(position).getGoods_img());holder.adapterTextview.setText(list.get(position).getGoods_name());holder.adapterTextview.setOnClickListener(new View.OnClickListener() {@Override
            public void onClick(View view) {EventBus.getDefault().postSticky(new EventBean(list.get(position).getGoods_img(),list.get(position).getGoods_name()));context.startActivity(new Intent(context, Main2Activity.class));}});}@Override
    public int getItemCount() {return list == null ? 0 : list.size();}static class IViewHolder  extends RecyclerView.ViewHolder{@BindView(R.id.adapter_simpledraweeview)SimpleDraweeView adapterSimpledraweeview;@BindView(R.id.adapter_textview)TextView adapterTextview;IViewHolder(View view) {super(view);ButterKnife.bind(this, view);}}
}

七。创建MainActivity类。

public class MainActivity extends Activity implements IMainView {@BindView(R.id.recycleview)RecyclerView recycleview;private MainPresenter presenter;private IApdater adapter;@Override
    protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);ButterKnife.bind(this);presenter = new MainPresenter(this);presenter.get();LinearLayoutManager manager = new LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false);adapter = new IApdater(this);recycleview.setLayoutManager(manager);recycleview.setAdapter(adapter);List<GoodsBriefBean> listBeans =  IApplication.session.getGoodsBriefBeanDao().loadAll();for(GoodsBriefBean bean : listBeans){System.out.println(bean.toString());}}@Override
    public void onSuccess(Bean bean) {adapter.addData(bean);}@Override
    public void onFailure(Exception e) {}
}
八。创建IGetDataBase请求接口。
 
      1,activity布局。
public interface IGetDataBase {//random=96333&encode=bf3386e14fe5bb0bcef234baebca2414
    @GET("/yunifang/mobile/category/list")Call<Bean> get(@Query("random") String key,@Query("encode") String encode);/**
     * post 璇锋眰
     * @param key
     * @return
     */
    @FormUrlEncoded
    @POST("/weixin/query")Call<Bean> post(@Field("key") String key);}
九。最后添加两布局。
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.lianxizongjie.MainActivity"><android.support.v7.widget.RecyclerView
        android:id="@+id/recycleview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></android.support.v7.widget.RecyclerView>
</android.support.constraint.ConstraintLayout>

2.条目布局创建laout。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="horizontal"
    android:layout_height="match_parent">
<com.facebook.drawee.view.SimpleDraweeView
    android:id="@+id/adapter_simpledraweeview"
    android:layout_width="100dp"
    android:layout_height="100dp" /><TextView
        android:id="@+id/adapter_textview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

这就完成了数据显示。

展示数据使用:recyclerview,retrofit,greendao,butterknife,eventbus,fresco。实现效果图列表。MVP模式。相关推荐

  1. Android Retrofit网络获取数据+Recyclerview展示数据

    先看一眼效果图: 那我们闲话少说,直接上代码了. 首先我们要在相对应的 build.gradle 文件中导入相应的依赖 implementation 'androidx.recyclerview:re ...

  2. 如何在Fragment碎片中展示数据

    //Fragment碎片展示数据 import android.os.Bundle; import android.support.annotation.NonNull; import android ...

  3. java el表达式 导航规则_诺禾:在jsp里面如何不写java代码展示数据(EL表达式的使用)...

    EL表达式可以简化jsp中写的java代码 在jsp里面如何不写java代码展示数据(EL表达式的使用) 在jsp里面如何不写java代码展示数据(EL表达式的使用) 在jsp里面如何不写java代码 ...

  4. oracle or使用速度快马_使用mysqld_exporter监控MySQL并展示数据

    mysqld_exporter是Prometheus用于监控MySQL指标的一个导出器,支持对MySQL 5.5以上进行监控.用来抓取mysql的相关信息,下面是mysqld_exporter 安装的 ...

  5. android 城市列表数据,用RecyclerView写的城市列表

    分享一下城市列表的网格布局样式的demo,代码里面包括网格布局和竖直列表布局两种样式. 网格样式: image.png 竖直列表样式: image.png 数据来源,本地的citylist.json城 ...

  6. Saiku Table展示数据合并bug修复(二十五)

    Saiku Table展示数据合并bug修复 Saiku以table的形式展示数据,如果点击了 非空的字段 按钮,则会自动进行数据合并,为空的数据行以及数据列都会自动隐藏掉. 首先我们应该定位问题: ...

  7. 利用bootstraptable展示数据,对数据进行排序分页等操作

    今天分享一下bootstraptable的相关技能点,由于第一次接触,所以刚开始碰了好多壁,于是趁现在过去不久,先总结总结. Bootstraptable简单的来说就是一个表格控件,但是这个表格可不是 ...

  8. 数据创造价值_展示数据并创造价值

    数据创造价值 To create the maximum value, urgency, and leverage in a data partnership, you must present th ...

  9. 表单及数据提交、表单的作用、服务端接收提交的数据、php处理数据流程、文件域及文件域中数据处理、php展示数据(响应)

    表单及数据提交: 表单的作用: 用于收集相关信息:html中有专门提交数据的标签,可以很容易的收集用户输入的信息,这个标签有两个重要的属性:action表单提交的地址和method以什么方式提交表单, ...

  10. layui表格展示数据时:返回的数据不符合规范,正确的成功状态码应为:code: 0

    1.今天,用django和layui结合,处理表格展示数据时,有数据的表格能正常显示列表,无数据的表格却提示了:返回的数据不符合规范,正确的成功状态码应为:"code": 0,于是 ...

最新文章

  1. ios NSLayoutConstraint
  2. batch normalization的原理和作用_springboot自动配置原理
  3. 【收藏】windows下 Mysql 错误 Can‘t open and lock privilege tables: Table ‘mysql.user‘ doesn‘t exist
  4. 虚拟机VirtualBox中Ubuntu无法全屏(终极解决方法)
  5. 顺序表和链表的优缺点理解
  6. 通过Rancher安装K8s
  7. css-阴影和超链接伪类
  8. 浅析ASP.NET 2.0的用户密码加密机制
  9. 十大排序算法:冒泡排序、选择排序、插入排序、希尔排序、归并排序、快速排序、堆排序、计数排序、桶排序、基数排序
  10. 抑制过拟合的方法之Dropout(随机删除神经元)
  11. Facebook对MySQL全表扫描性能的改进
  12. Android -- 无线网络配置信息的管理者WifiConfigStore简介
  13. mpg文件怎么转换成mp4
  14. 怎么用计算机做目录,word目录怎么自动生成详细教程
  15. html5制作一个六角星,儿童节手工折纸六角星制作教程
  16. 编程之美-2.3-寻找发帖“水王”
  17. 【Fiddler】如何使用Fiddler中的Fiddler插件下载钉钉直播回放
  18. 宏任务和微任务的详解
  19. 【解决】from win32com.shell import shellcon, shell ImportError: DLL load failed: 找不到指定的程序。
  20. JavaSE基础(79) BigInteger(能够存取比Long更大的整数,可以任意大小)

热门文章

  1. 被故事选中,没资格懵懂。
  2. Jmeter分布式压力测试全过程(阿里云ECS)
  3. IDEA中java文件出现小黄色的J
  4. 阿里云王坚“骗”马云10个亿,被骂四年都忍了,最后还回4500亿
  5. move_base导航框架中recovery_behaviors
  6. verilog 实现9位有符号乘法器
  7. 为subclipse配置http代理,解决“RA layer request failed, Unable to connect to a repository at URL ... 错误
  8. 《Java核心技术:卷I 基础知识》第1章 Java 程序设计概述 阅读与重点标记
  9. 计算机科学个人陈述中文,留学文书写作范例-计算机科学(个人陈述)
  10. “三天打鱼,两天晒网”问题