首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >回收器滚动上的回收站索引位置mess数据

回收器滚动上的回收站索引位置mess数据
EN

Stack Overflow用户
提问于 2017-03-06 16:02:00
回答 1查看 321关注 0票数 1

第一次数据填充正确。但是当我从下往上滚动recyclerview时,所有数据及其位置都乱七八糟。我尝试添加itemViewHolder.setIsRecyclable(false); setHasStableIds(false),但在尝试填充水平回收器视图的垂直回收器视图中没有任何效果

代码语言:javascript
复制
public HomeRecyclerViewAdapter(Context context, Home homeModel) {
        this.context = context;
        this.homeModel = homeModel;
    }
 @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        if (viewType == TYPE_HEADER) {
            View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.homefragment_header, parent, false);
            return new HeaderViewHolder(v);
        } else if (viewType == TYPE_ITEM) {
            View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_homefragment, parent, false);
            return new ItemViewHolder(v);
        } else if (viewType == PRODUCT_ITEM) {
            View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_productlines, parent, false);
            return new ProductLinesItemHolder(v);
        } else if (viewType == SHOPS_ITEM) {
            View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_productlines, parent, false);
            return new ShopsOfWeekItemHolder(v);
        }
        return null;
    } 
@Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (position == 0) {
            if (holder instanceof HeaderViewHolder) {
              // load data in slider
            }
        } else if (holder instanceof ItemViewHolder) {
            ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
            if (homeModel.getCategories().get(0) != null) {
                if (position == 1) {
                     //load data in category recyclerview
                    holder.setIsRecyclable(false);
                }
            }
        } else if (holder instanceof ProductLinesItemHolder) {
            ProductLinesItemHolder itemViewHolder = (ProductLinesItemHolder) holder;
            if (homeModel.getProductLines() != null) {
                if (position > 1 && pos <= homeModel.getProductLines().size()-1) {
                    Log.d("HomeRecycler","pos:"+pos);
                    Log.d("HomeRecycler","position:"+ (position-2));
                        setRecyclerView(2, itemViewHolder);
                        Log.d("HomeRecycler","pos:"+homeModel.getProductLines().get(pos).getName());
                        itemViewHolder.txtProductName.setText(homeModel.getProductLines().get(pos).getName());
                        itemViewHolder.txtViewAllShops.setVisibility(View.GONE);
                        populateProductLinesItem(itemViewHolder, homeModel.getProductLines().get(pos));
                        pos = pos + 1;

                }
            }
        }
private void populateProductLinesItem(ProductLinesItemHolder itemViewHolder, ProductLines productLines) {
        ProductLinesItemAdapter productLinesItemAdapter = new ProductLinesItemAdapter(context, productLines.getItems(), clickEventOfProductsItemListener);
        itemViewHolder.prodLinesRecyclerView.setAdapter(productLinesItemAdapter);
        productLinesItemAdapter.notifyDataSetChanged();
    }

有没有人能推荐一下?如何避免这个问题?更多代码:https://gist.github.com/anonymous/7785cdd97b5c27886c81f321c8965930

EN

回答 1

Stack Overflow用户

发布于 2017-03-10 19:26:59

基于这一点:

,但是当我从下往上滚动回收器视图时,所有的数据和它的位置都乱了。

这里有一个类似的问题,这里是解决它的SO Post

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42620387

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档