IndexOutOfBoundsException: Inconsistency detected. Invalid item position
来源:互联网 发布:c 游戏编程 编辑:程序博客网 时间:2024/05/20 22:30
做项目遇到个问题:使用RecyclerView
+ SwipeRefreshLayout
时,下拉刷新,接着连续快速上拉。
程序直接奔溃! 接着一脸懵逼。。
查看日志看到报错IndexOutOfBoundsException: Inconsistency detected. Invalid item position
…
并且错误并没有报到自己代码中,是在RecycleView 中崩溃的。
原因:
当list.clear()
之后,这时迅速上滑list为空,导致RecyclerView
要加载数据的时候,找不到数据源了,造成crash
解决办法:
更新,加载数据时,禁止滑动
设置全局变量mIsRefreshing
boolean mIsRefreshing = false;
RecyclerView
设置OnTouchListener
mRecyclerView.setOnTouchListener( new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return mIsRefreshing; } });
原理就是:设置TouchListener
,通过设置mIsRefreshing
的值当请求数据时(下拉刷新,上拉加载)并返回true
,RecyclerView
将无法滑动,无法点击里面的Item。即无法回调OnScrollListener
和OnItemClickListener
方法。请求结束后返回false
,正常回调OnScrollListener
和OnItemClickListener
方法。
还有一个更简单的办法:
在list.clear();
之后notify
一下。有一个缺点就是会闪一下。
1 0
- IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid item position 解决方案
- RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid item position …
- RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- 成功解决RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 的解决方案
- java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- Android中RecyclerView出现Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position的一种规避方式
- java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 6(offset:6).state
- 解决java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 1(offset:1)
- Error: Inconsistency detected. Invalid item position 11(offset:11).state:37 RecyclerView
- RecyclerView:IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter
- 解决IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter
- java高级_工具类_数学类
- Spring动态代理之详细DEBUG日志模式
- Could Not Get the Value for Parameter compilerId for Plugin Execution
- 七大查找算法
- Laravel5.2.45初级系列教程(1)
- IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- web程序在win7_64bit连接Oracle调试要点,应对Oracle的(x86)bug
- 天猫,京东各大网站锚点的跳转
- 用户管理
- mysql问题:1、本地连接不了mysql服务器,连接3306端口失败
- pycharm 汉化
- 51nod_1134 最长递增子序列(O(n*logn))
- LeetCode/TwoSum Java
- k8s集群部署DNS服务发现