天天看点

BaseQuickerAdapter的多条目类型展示 18.4k

https://github.com/CymChad/BaseRecyclerViewAdapterHelper
//adapter
api 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.42'  18.4k star      

1 示例

public class QuestionAdapter extends BaseQuickAdapter<QuestionListBean.RowsBean, BaseViewHolder> {
    private static final int TYPE_QUESTION_NO_PIC = 0;
    private static final int TYPE_QUESTION_ONE_PIC = 1;
    private static final int TYPE_QUESTION_THREE_PIC = 3;

    //刷新布局
    public QuestionAdapter(@Nullable List<QuestionListBean.RowsBean> data) {
//        super(R.layout.item_question, data);
        super(data);
        //Step.1
        setMultiTypeDelegate(new MultiTypeDelegate<QuestionListBean.RowsBean>() {
            @Override
            protected int getItemType(QuestionListBean.RowsBean rowsBean) {
                if (rowsBean.vcPicUrls == null || rowsBean.vcPicUrls.size() == 0) {
                    return TYPE_QUESTION_NO_PIC;
                } else if (rowsBean.vcPicUrls.size() < 3) {
                    return TYPE_QUESTION_ONE_PIC;
                } else {
                    return TYPE_QUESTION_THREE_PIC;
                }
            }
        });
        //Step.2
        getMultiTypeDelegate()
                .registerItemType(TYPE_QUESTION_NO_PIC, R.layout.item_question)
                .registerItemType(TYPE_QUESTION_ONE_PIC, R.layout.item_question_onepic)
                .registerItemType(TYPE_QUESTION_THREE_PIC, R.layout.item_question_threepic);
    }

    @Override
    protected void convert(BaseViewHolder helper, QuestionListBean.RowsBean item) {
        switch (helper.getItemViewType()) {
            case TYPE_QUESTION_NO_PIC:
                break;
            case TYPE_QUESTION_ONE_PIC:
                Glide.with(mContext).load(item.vcPicUrls.get(0)).into((ImageView) helper.getView(R.id.iv_question_pic));
                break;
            case TYPE_QUESTION_THREE_PIC:
                Glide.with(mContext).load(item.vcPicUrls.get(0)).into((ImageView) helper.getView(R.id.iv_question_pic1));
                Glide.with(mContext).load(item.vcPicUrls.get(1)).into((ImageView) helper.getView(R.id.iv_question_pic2));
                Glide.with(mContext).load(item.vcPicUrls.get(2)).into((ImageView) helper.getView(R.id.iv_question_pic3));
                break;
        }
    }
}