美文网首页
recyclerview bug : IndexOutOfBou

recyclerview bug : IndexOutOfBou

作者: 十二书 | 来源:发表于2019-05-05 15:51 被阅读0次

    recyclerview bug : IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter

    分析源码,

    首先,notifyDataSetChanged一定要在主线程执行;否则报错,非UI线程不能操作view。

    其次,报错其实是主线程有child view 更新的时候,发现child的position小于adapter的getItemCount,代码里面就会直接报错。

    所以,只要保证adapter的getItemCount的修改,和notifyDataSetChanged同时在主线程执行,中间没有被打断即可。也就是把两个代码放在一起。

    或者说,notifyDataSetChanged的时候,应该保证getItemCount的结果是对的

    相关文章

      网友评论

          本文标题:recyclerview bug : IndexOutOfBou

          本文链接:https://www.haomeiwen.com/subject/hgtfpxtx.html