今天使用RecyclerView时,上下两个RecyclerView,在实现下拉刷新时,报错:

java.lang.IndexOutOfBoundsException: Inconsistency detected.
  Invalid view holder adapter positionViewHolder{56798b2 position=2 id=-1, oldPos=2, pLpos:-1 scrap [attachedScrap] tmpDetached no parent}

在网上看到这个方法可以暂时性解决问题

其实也不是什么解决方法,只是把这个异常捕获了,不让他奔溃了,这个问题的终极解决方案还是得让google去修复。

1、创建一个类LinearLayoutManagerWrapper继承LinearLayoutManager,重写onLayoutChildren方法

  1. public class WrapContentLinearLayoutManager extends LinearLayoutManager {
  2. public WrapContentLinearLayoutManager(Context context) {
  3. super(context);
  4. }
  5. public WrapContentLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
  6. super(context, orientation, reverseLayout);
  7. }
  8. public WrapContentLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
  9. super(context, attrs, defStyleAttr, defStyleRes);
  10. }
  11. @Override
  12. public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
  13. try {
  14. super.onLayoutChildren(recycler, state);
  15. } catch (IndexOutOfBoundsException e) {
  16. e.printStackTrace();
  17. }
  18. }
  19. }

2、设置RecyclerView的布局管理为WrapContentLinearLayoutManager对象

  1. mRecyclerView.setLayoutManager(new WrapContentLinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));

RecycleView Bug:java.lang.IndexOutOfBoundsException: Inconsistency detected.的更多相关文章

  1. RecycleView错误: java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder

    1.错误 java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positi ...

  2. 滑动RecyclerView时出现异常: java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 6(offset:6).state:30

    RecyclerView 存在的一个明显的 bug 一直没有修复: java.lang.IndexOutOfBoundsException: Inconsistency detected. Inval ...

  3. Recyclerview 出现 java.lang.IndexOutOfBoundsException: Inconsistency detected 异常

    使用 RecyclerView 的时候报错 java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view hold ...

  4. RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter的解决方案(转)

    转自:RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter的解 ...

  5. Android中RecyclerView出现java.lang.IndexOutOfBoundsException

    在RecyclerView更细数据时出现java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder ...

  6. java.lang.IndexOutOfBoundsException: setSpan (35 ... 35) ends beyond length 28

    /************************************************************************************* * java.lang.I ...

  7. 日志异常:java.lang.NoClassDefFoundError: Could not initialize class org.slf4j.impl.StaticLoggerBinder

    今天启动开发的项目,碰到了一个日志上的bug:java.lang.NoClassDefFoundError: Could not initialize class org.slf4j.impl.Sta ...

  8. sparksql读取hive数据报错:java.lang.RuntimeException: serious problem

    问题: Caused by: java.util.concurrent.ExecutionException: java.lang.IndexOutOfBoundsException: Index: ...

  9. maven发布到tomcat报错: Publishing failed Could not publish to the server. java.lang.IndexOutOfBoundsException

    eclipse中将maven项目发布到tomcat报错时: Publishing failed Could not publish to the server. java.lang.IndexOutO ...

随机推荐

  1. 浅谈 Vue v-model指令的实现原理 - 如何利用v-model设计自定义的表单组件

    原文请点击此链接  链接1 http://www.7zhang.com/index/cms/read/id/234515.html  链接2 http://blog.csdn.net/yangbing ...

  2. 理解BitSet

    先来看几道面试题: 1.统计40亿个数据中没有出现的数据,将40亿个不同数据进行排序. 2.现在有1千万个随机数,随机数的范围在1到1亿之间,要求写出一种算法,将1到1亿之间没有在随机数中的数求出来. ...

  3. endnote的安装和使用必备的几个步骤(简单有效整理版)

    endnote:文献检索和管理工具 一 准备工作 endnote大客户版/破解版获取地址:http://blog.sina.com.cn/s/blog_6de000c20101n7ac.html 之所 ...

  4. [Leetcode] 2.Add Two Numbers(List To Long,模拟)

    本题题意是指将两个数倒序存储在链表中,再将两数之和同样存储在链表中输出. 我最开始的思路是将每一位相加,再考虑是否进位,但这时就需要考虑一些情况,比较麻烦. 于是我决定采取另一种在网上新学到的方法:这 ...

  5. [转]matlab语言中的assert断言函数

    MATLAB语言没有系统的断言函数,但有错误报告函数 error 和 warning.由于要求对参数的保护,需要对输入参数或处理过程中的一些状态进行判断,判断程序能否/是否需要继续执行.在matlab ...

  6. BZOJ 1818 内部白点(离散化+树状数组)

    此题就是1227 的弱化版. 画个图或者稍微证明一下就能够知道,一定不会超过一次变换. 那么我们只需要统计有多少个白点会变黑,换句话说就是有多少个白点上下左右都有黑点. 离散化横坐标,因为没有黑点在的 ...

  7. [BZOJ5339] [TJOI2018]教科书般的亵渎

    题目链接 BZOJ题面. 洛谷题面. Solution 随便推一推,可以发现瓶颈在求\(\sum_{i=1}^n i^k\),关于这个可以看看拉格朗日插值法. 复杂度\(O(Tm^2)\). #inc ...

  8. BZOJ1009:[HNOI2008]GT考试——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=1009 Description 阿申准备报名参加GT考试,准考证号为N位数X1X2....Xn(0&l ...

  9. [Leetcode] permutations ii 全排列

    Given a collection of numbers that might contain duplicates, return all possible unique permutations ...

  10. HDOJ(HDU).1003 Max Sum (DP)

    HDOJ(HDU).1003 Max Sum (DP) 点我挑战题目 算法学习-–动态规划初探 题意分析 给出一段数字序列,求出最大连续子段和.典型的动态规划问题. 用数组a表示存储的数字序列,sum ...