IndexOutOfBoundsException:检测到不一致。无效的商品位置-RecylerView

时间:2018-11-08 06:49:37

标签: android android-recyclerview indexoutofboundsexception recycler-adapter

  

IndexOutOfBoundsException:检测到不一致。无效的商品位置-RecylerView

我有两个回收站视图,分别是RecylerA和RecylerB 当RecyclerB位于最后一个位置时,我会加载剩余的数据并通知RecyclerB适配器。它对我来说很好用,但是在加载RecyclerB时,我尝试单击RecyclerA,RecylerA实际上清除了RecylerB适配器并通过API加载了新数据,几乎所有时间对我来说都很好。但是有一段时间我遇到如下问题,

 java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 24(offset:24).state:36 android.support.v7.widget.RecyclerView{620771f VFED..... ...
        at android.support.v7.widget.RecyclerView$Recycler.a(Unknown Source:389)
        at android.support.v7.widget.GapWorker.prefetchPositionWithDeadline(Unknown Source:14)
        at android.support.v7.widget.GapWorker.flushTaskWithDeadline(Unknown Source:15)
        at android.support.v7.widget.GapWorker.flushTasksWithDeadline(Unknown Source:22)
        at android.support.v7.widget.GapWorker.a(Unknown Source:3)
        at android.support.v7.widget.GapWorker.run(Unknown Source:71)
        at android.os.Handler.handleCallback(Handler.java:790)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6626)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)

我尝试在StackOverflow上看到的几乎所有解决方案,例如

mRecyclerViewproduct.getRecycledViewPool().clear();
mRecyclerViewproduct.setItemAnimator(null);

在通知适配器之前。此外,还需要额外的时间来通知适配器。使用位置等更新通知适配器。但是没有解决方案对我有用。有什么新想法或解决方案吗?

更新: RecyclerA的适配器如下(viewHolder)

if (selectedPosition == position) {
            holder.list_rv_productchip.setTextColor(Color.WHITE);
            holder.itemView.setBackground(context.getResources().getDrawable(R.drawable.chipselected));
        } else {
            holder.list_rv_productchip.setTextColor(Color.BLACK);
            holder.itemView.setBackground(context.getResources().getDrawable(R.drawable.quantityblack));
        }

        holder.itemView.setOnClickListener(view -> {
            selectedPosition = position;
            notifyDataSetChanged();
            ((CategorywiseProductlistActivity) context).loadingpageflag = true;
            ((CategorywiseProductlistActivity) context).filterdata = "{\"filter\":{ } }";
            constantsVariables.category_wise_product_paging=1;
            ((CategorywiseProductlistActivity) context).makeCategorycurrentidtochip(subCategories.get(position).getId());
            if (subCategories.get(position).getName().matches("All Items")) {
                ((CategorywiseProductlistActivity) context).titleallproducts.setText("All in " + ((CategorywiseProductlistActivity) context).headtitle);
            } else {
                ((CategorywiseProductlistActivity) context).titleallproducts.setText("All in " + subCategories.get(position).getName());
            }
            ((CategorywiseProductlistActivity) context).Categorycurrentid = "" + subCategories.get(position).getId();
            ((CategorywiseProductlistActivity) context).displayproducts(subCategories.get(position).getId(), "{\"filter\":{ } }");
        });

0 个答案:

没有答案
相关问题