recyclerview配合BaseRecyclerViewAdapterHelper

1、引入

implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.40'
private void initData() {
    //添加图片到集合
    list.add(R.mipmap.p1);
    list.add(R.mipmap.p2);
    list.add(R.mipmap.p3);
    list.add(R.mipmap.p4);
    list.add(R.mipmap.p5);
    list.add(R.mipmap.p6);
    list.add(R.mipmap.p7);
    list.add(R.mipmap.p8);
    list.add(R.mipmap.p9);
    list.add(R.mipmap.p10);
    //2列
    GridLayoutManager gridLayoutManager = new GridLayoutManager(this.getContext(),2);
    rcyLiebiao.setLayoutManager(gridLayoutManager);
    shangPinAdapter = new ShangPinAdapter(R.layout.item_shangpin, list);
    rcyLiebiao.setAdapter(shangPinAdapter);
}
public class ShangPinAdapter extends BaseQuickAdapter<Integer, BaseViewHolder> {

    public ShangPinAdapter(int layoutResId, @Nullable List<Integer> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, Integer item) {
        helper.setImageResource(R.id.item_sp,item);
    }

}

简单快捷明鸟

猜你喜欢

转载自blog.csdn.net/wjjPig1995/article/details/117515973
今日推荐