recycleView 遇到IndexOutOfBoundsException 及解决
2016-04-17 16:55
274 查看
事情是这样的
我在activity 中继承的MVPView,通过presenter加载输入,然后调用MVPview中的下面这个方法"
结果报了下面这个错误
排除了List的数组越界问题后,我想到了可能是recycleView的一个BUG.
果然,在Google一番之后发现确实有这个问题
按照上面这个回答,我改成了
果然问题解决了.不过又转念一想,既然这这个notify的问题,或许,这样试试?
不要老是想着是个BUG,也许是自己的调用不和规范呢?
我在activity 中继承的MVPView,通过presenter加载输入,然后调用MVPview中的下面这个方法"
@Override public void setLocationData(List<Location> locationData) { locationList.clear(); locationList.addAll(locationData); chooseLocationAdapter.notifyItemRangeInserted(0, locationData.size()+1); // chooseLocationAdapter.notifyDataSetChanged(); }
结果报了下面这个错误
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder
排除了List的数组越界问题后,我想到了可能是recycleView的一个BUG.
果然,在Google一番之后发现确实有这个问题
1 down vote It is a bug of RV, see the discussion here. In most cases, use notifyDataSetChanged() will avoid this crash, but it will kill Animation and Performance.
按照上面这个回答,我改成了
chooseLocationAdapter.notifyDataSetChanged();
果然问题解决了.不过又转念一想,既然这这个notify的问题,或许,这样试试?
<span style="white-space:pre"> </span>locationList.clear(); chooseLocationAdapter.notifyDataSetChanged(); locationList.addAll(locationData); chooseLocationAdapter.notifyItemRangeInserted(0, locationData.size()+1);是的,清除数据后notify一次,加载数据在notify一次,问题解决了!
不要老是想着是个BUG,也许是自己的调用不和规范呢?
相关文章推荐
- Linux 时间定时同步操作
- MapReduce的过程(2)
- VB中几种循环结构
- MapReduce的过程(2)
- Andoird Studio 错误: 非法字符: '\ufeff' 解决方案。
- 使用supervisor提高nodejs开发效率
- 团队目标和细节估计
- spring bean之间的关系:继承;依赖
- POJO(PO)与javaBean的比较、以及DTO的说明
- 支付宝当面付之扫码支付“无效签名”
- (4.5.4.1)android studio进行Unit测试和ActivityInstrumentationTestCase2测试
- 树, 二叉树, 二叉搜索树
- Python中的字典(dict)
- 抄袭证据之中的一个CMM与CMMI的名称
- ffmpeg工作流程分析-3
- shell中的循环结构
- 【机器学习】Matlab中实现QQ-plot的一个好工具gqqplot
- for each循环使用说明
- 俄罗斯乘法
- iOS推送本地通知 Push Notifications: local part