RecyclerView的brvah实现

//导入依赖

implementation 'com.android.support:design:28.0.0'
    implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.30'

//如果导入失败 在工作空间中配置

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

//布局文件中






    
    
        
        
    



//M层中

OkGo.get(Constart.SHOPPING_URL).execute(new StringCallback() {
            @Override
            public void onSuccess(Response response) {
                String responseDate=response.body().toString();
                Gson gson=new Gson();
                Jsonbean jsonbean=gson.fromJson(responseDate,Jsonbean.class);
                callBack.onCallBack(jsonbean);
            }
        });

//主页面showData方法中

ArrayList beanList = (ArrayList) jsonbean.getData();
//瀑布流StaggeredGridLayoutManager manager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
        // 线性LinearLayoutManager manager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false);
         //网格GridLayoutManager manager = new GridLayoutManager(context, 2,GridLayoutManager.VERTICAL,false);
        rvContainer.setLayoutManager(manager);
        ShowAdapter showAdapter=new ShowAdapter(R.layout.recyclerview_item_layout,beanList);
        rvContainer.setAdapter(showAdapter);

//适配器中 Jsonbean.DataBean,是自己写的bean类
继承BaseQuickAdapter

 @Override
    protected void convert(BaseViewHolder helper, Jsonbean.DataBean item) {
        if (item.getList().size()!=0){
            if (null!=item.getList().get(0).getTitle()){
                helper.setText(R.id.tv_title,item.getList().get(0).getTitle());
            }
            if (null!=item.getList().get(0).getPrice()+""){
                helper.setText(R.id.tv_price,item.getList().get(0).getPrice()+"");
            }
            if (null!= item.getList().get(0).getImages()){
                String images = item.getList().get(0).getImages();
                String[] imageDetails = images.split("\\|");
                //获取第一张图片
                Glide.with(mContext).load(imageDetails[0]).into((ImageView) helper.getView(R.id.iv_icon));
            }
        }

    }

你可能感兴趣的:(RecyclerView的brvah实现)