CymChad / BaseRecyclerViewAdapterHelper

BRVAH:Powerful and flexible RecyclerAdapter
http://www.recyclerview.org/
MIT License
24.33k stars 5.16k forks source link

树状列表有bug,数据会自动添加 #2055

Closed love-aqua closed 6 years ago

love-aqua commented 6 years ago

public class QuickExpandableAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder> { public static final int TYPE_LEVEL_0 = 0; public static final int TYPE_LEVEL_1 = 1;

/**
 * Same as QuickAdapter#QuickAdapter(Context,int) but with
 * some initialization data.
 *
 * @param data A new list is created out of this one to avoid mutable list
 */
public QuickExpandableAdapter(List<MultiItemEntity> data) {
    super(data);
    addItemType(TYPE_LEVEL_0, R.layout.view_expand_0);
    addItemType(TYPE_LEVEL_1, R.layout.view_expand_1);

// addItemType(TYPE_LEVEL_1, R.layout.list_item_top); }

@Override
protected void convert(final BaseViewHolder helper, MultiItemEntity item) {
    switch (helper.getItemViewType()){
        case TYPE_LEVEL_0:
            final TitleExpandItem item0 = (TitleExpandItem) item;
            helper.setText(R.id.expand_list_item0_tv,item0.getTitle());
            helper.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int pos = helper.getAdapterPosition();
                    if (item0.isExpanded()){
                        collapse(pos);

// ToastUtils.showTastyInfo("收起:" + item0.getTitle()); }else { expand(pos); // ToastUtils.showTastyInfo("展开:" + item0.getTitle()); } } }); break; case TYPE_LEVEL_1: int parentPosition = getParentPosition(item); TitleExpandItem titleExpandItem = (TitleExpandItem) getData().get(parentPosition); RecyclerView recyclerView = helper.getView(R.id.expand_list_item1_tv); BaseQuickAdapter baseQuickAdapter = new BaseQuickAdapter<PopItemModel,BaseViewHolder>(R.layout.grid_item,titleExpandItem.getSubItems()) { @Override protected void convert(BaseViewHolder helper, PopItemModel item) { TextView tv_title = helper.getView(R.id.tv_title); tv_title.setText(item.item); helper.addOnClickListener(R.id.tv_title); if (item.isSelect){ tv_title.setBackgroundResource(R.drawable.text_bg3); }else{ tv_title.setBackgroundResource(R.drawable.text_bg2); } } }; recyclerView.setLayoutManager(new GridLayoutManager(mContext,3)); recyclerView.setAdapter(baseQuickAdapter);

            baseQuickAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
                @Override
                public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                    //改变选中的值

// if (R.id.tv_title == view.getId()){ // for (int i = 0; i < item1.list.size(); i++) { // if (position == i){ // item1.list.get(i).isSelect = true; // }else{ // item1.list.get(i).isSelect = false; // } // } // } // baseQuickAdapter.notifyDataSetChanged(); } }); break; } } }

我adapter如上,但是当点击一个数据的时候,本来是这样的数据结构的。 qq 20180314094843 点击后,数据自己变成这样了。 qq 20180314094958 请问是怎么回事啊?我调试了好久都没找到问题,而且我根本没改变过数据。数据结构在点击就变了。

saga87 commented 6 years ago

我在子项EditText输入内容,下拉后面每隔几个子项也会添加这个内容。数据错乱

AllenCoder commented 6 years ago

editText的输入被复用,数据的绑定要基于Model层,不在直接在view层处理数据的记录

love-aqua commented 6 years ago

还是搞不掂这个问题,不知道为啥会列表自动添加这些数据?