今天使用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. python爬虫--打开爬取页面

    def requests_view(response): import webbrowser requests_url = response.url base_url = '<head>& ...

  2. bzoj3998-弦论

    给定一个长度为\(n(n\le 5\times 10^5)\)的字符串,求它的第\(k\)小字串.有两种模式: \(Type=0\),不同位置的相同字串只算一个 \(Type=1\),不同位置相同字串 ...

  3. 洛谷 P3119 [USACO15JAN]草鉴定Grass Cownoisseur 解题报告

    P3119 [USACO15JAN]草鉴定Grass Cownoisseur 题目描述 约翰有\(n\)块草场,编号1到\(n\),这些草场由若干条单行道相连.奶牛贝西是美味牧草的鉴赏家,她想到达尽可 ...

  4. JSP页面中的Meta标签详解

    Meta标签详解 相信大家在平时开发中最常接触的页面就是html和jsp了,可在这两个页面中有一个Meta标签你天天都会看见,可是你真的了解这个标签的一些其他用处吗?今天给大家介绍一些该标签的其他应用 ...

  5. 简述JavaScript的类与对象

    JavaScript语言是动态类型的语言,基于对象并由事件驱动.用面向对象的思想来看,它也有类的概念.JavaScript 没有class关键字,就是用function来实现. 1. 实现方式及变量/ ...

  6. 爬虫实例——爬取淘女郎相册(通过selenium、PhantomJS、BeautifulSoup爬取)

    环境 操作系统:CentOS 6.7 32-bit Python版本:2.6.6 第三方插件 selenium PhantomJS BeautifulSoup 代码 # -*- coding: utf ...

  7. HDU2121:Ice_cream’s world II (虚根+有向图最小生成树)

    Ice_cream’s world II Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  8. 再来说一说sudo

    app        ALL = (ALL:ALL) ALL eric.zhan ALL = (app : app) ALLDefaults:eric.zhan runas_default=app 如 ...

  9. DOM案例五星评分控件

    模仿网页上评分的五个五星. <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> < ...

  10. getQueryString----获取url中得参数

    /** * 获取url中得参数 * @param name * @returns {null} */ window.getQueryString = function (name) { var reg ...