IndexOutOfBoundsException: Inconsistency detected. Invalid item position
2017-03-08 19:55
351 查看
前言:不知道是不是我的as没更新还是更新出错啊,今天用RecyclerView时竟然会出现一个奇怪的bug
问题:java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position…
原因:据说是:RecyclerView 下拉刷新时,若绑定的 List 对象在更新数据之前进行了 clear,而这时用户紧接着迅速上滑 RV,就会造成崩溃
解决办法:
方法一:在mRecyclerView.setLayoutManager()中去解决:
(1)LinearLayoutManager布局:
创建一个类,继承LinearLayoutManager,在onLayoutChildren()方法中去捕捉该异常:
然后再在mRecyclerView.setLayoutManager(new NpaLinearLayoutManager(参数....));
即可
(2)GridLayoutManager布局:
同理,创建一个类继承GridLayoutManager,只不过,这里重写supportsPredictiveItemAnimations()方法,返回false:
方法二:设置clear数据时,让mRecyclerView暂时失去滑动
而我就是用方法一解决的
问题:java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position…
原因:据说是:RecyclerView 下拉刷新时,若绑定的 List 对象在更新数据之前进行了 clear,而这时用户紧接着迅速上滑 RV,就会造成崩溃
解决办法:
方法一:在mRecyclerView.setLayoutManager()中去解决:
(1)LinearLayoutManager布局:
创建一个类,继承LinearLayoutManager,在onLayoutChildren()方法中去捕捉该异常:
/** * 重写该方法,去捕捉该异常 * @param recycler * @param state */ @Override public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) { try{ super.onLayoutChildren(recycler, state); }catch (IndexOutOfBoundsException e){ e.printStackTrace(); } }
然后再在mRecyclerView.setLayoutManager(new NpaLinearLayoutManager(参数....));
即可
(2)GridLayoutManager布局:
同理,创建一个类继承GridLayoutManager,只不过,这里重写supportsPredictiveItemAnimations()方法,返回false:
/**重写该方法,返回false * */ @Override public boolean supportsPredictiveItemAnimations() { return false; }然后,再在mRecyclerView.setLayoutManager(new NapGridLayoutManager(参数....));即可
方法二:设置clear数据时,让mRecyclerView暂时失去滑动
mRecyclerView.setOnTouchListener( new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (mIsRefreshing) { return true; } else { return false; } } } );
而我就是用方法一解决的
相关文章推荐
- java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 6(offset:6).state
- Android中IndexOutOfBoundsException: Inconsistency detected. Invalid item position 1(offset:1).state:4
- IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 的解决方案
- 成功解决RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- 【转载】Android 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 1(offset:1)
- java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- 滑动RecyclerView时出现异常: java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 6(offset:6).state:30
- RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid item position 解决方案
- java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionVie
- RecyclerView内部BUG: java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item positio
- IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder
- IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter notifyItemRangeRemove