Error: Inconsistency detected. Invalid item position 11(offset:11).state:37 RecyclerView
来源:互联网 发布:俄罗斯地铁软件 编辑:程序博客网 时间:2024/06/03 11:46
重现的方法是:使用 RecyclerView 加官方下拉刷新的时候,如果绑定的 List 对象在更新数据之前进行了 clear,而这时用户紧接着迅速上滑 RV,就会造成崩溃,而且异常不会报到你的代码上,属于RV内部错误。初次猜测是,当你 clear 了 list 之后,这时迅速上滑,而新数据还没到来,导致 RV 要更新加载下面的 Item 时候,找不到数据源了,造成 crash.
解决方案:
1、就是在刷新,也就是 clear 的同时,让 RecyclerView 暂时不能够滑动,之后再允许滑动即可。代码就是在 RecyclerView 初始化的时候加上是否在刷新进而拦截手势:
mRecyclerView.setOnTouchListener( new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (mIsRefreshing) { return true; } else { return false; } } });2.可以在clear list的时候通知recyclerVIew.
Observable.create(new Observable.OnSubscribe<Integer>() { @Override public void call(Subscriber<? super Integer> subscriber) { try { getLogCount(startTime, endTime); calibrateEntryList = showCalirateByPageIndex(startTime, endTime); subscriber.onNext(calibrateEntryList.size()); subscriber.onCompleted(); } catch (ParseException e) { e.printStackTrace(); } } } ).subscribeOn(Schedulers.io()).doOnSubscribe(new Action0() { @Override public void call() { restoreCurrentLogCount(); getView().notifyDataSetChanged(); } }).subscribeOn(AndroidSchedulers.mainThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber() { @Override public void onCompleted() { addItems(calibrateEntryList); getView().notifyDataSetChanged(); } @Override public void onError(Throwable e) { Log.i(TAG, "onError: %s", e); } @Override public void onNext(Object o) { int requestCount = ((Integer) o).intValue(); Log.i(TAG, "onNext: requestCount" + requestCount); getView().changeLoadMoreByCount(MaxCount, requestCount); } });
public void restoreCurrentLogCount() { mCurrentLogCount = 0; mDataAdapter.cleanAll(); }//里面调用了list.clear可以看到我使用Rx在观察者行动前,清空list 并notifydatasetChange。问题解决。
0 0
- Error: Inconsistency detected. Invalid item position 11(offset:11).state:37 RecyclerView
- java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 6(offset:6).state
- 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
- IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- IndexOutOfBoundsException: Inconsistency detected. Invalid item position
- 解决java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 1(offset:1)
- 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
- java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position的一种规避方式
- RecyclerView:IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter
- RecyclerView异常:Inconsistency detected. Invalid view holder adapter positionViewHolder
- hadoop 出现 failed to create file because current leaseholder is trying to recreate file.
- Android toast弹出时间自定义
- LuceneDemo
- Spring 框架基于注解
- windows下开发PHP扩展dll(无需Cygwin)
- Error: Inconsistency detected. Invalid item position 11(offset:11).state:37 RecyclerView
- NYOJ 79.拦截导弹(动态规划)
- 利用cmd(Windows)编译c\c++源程序
- 【Linux c】socket+thread【preIot project】
- Android沉浸式状态栏SystemBarTint的使用方法
- JSON与XML的优缺点比较
- 内部命令VS外部命令
- UVA 796 Critical Links 求桥 .
- android端实现http服务器,具备文件上传等功能,纯JAVA实现,无依赖包