youlookwhat / ByRecyclerView

🔥 RecyclerView 下拉刷新、上拉松手/自动加载更多、item点击/长按、item局部刷新、头布局/尾布局/状态布局、万能分割线、Skeleton骨架图、极简adapter、嵌套滑动置顶
https://youlookwhat.github.io/ByRecyclerView
Apache License 2.0
798 stars 139 forks source link

setLoadMoreEnabled() & addData() 导致异常 #26

Closed CxmyDev closed 3 years ago

CxmyDev commented 3 years ago

setLoadMoreEnabled() & addData(),2 个 Api 一起调用,会导致 IndexOutOfBoundsException 异常;

Adapter 使用的 BaseRecyclerAdapter 的子类;

场景:分页场景下,LoadMore 至最后一页时,addData() 的同时,需调用 setLoadMoreEnabled(false) 禁用 LoadMore;

java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionSimpleViewHolder{347ed11 position=18 id=-1, oldPos=16, pLpos:16 scrap [attachedScrap] tmpDetached no parent}

youlookwhat commented 3 years ago

感谢提出,我看一下

youlookwhat commented 3 years ago

这个问题很多人遇到过,也给了解决方案,主要是继承LayoutManager将发生异常的方法try一下,具体使用:ByLinearLayoutManager。在分割线-线性drawable那个示例中可以看到

CxmyDev commented 3 years ago

嗯,还是觉得直接 catch 住处理不太好; 我这边临时的解决方案是将 rv. setLoadMoreEnabled() 放在 rv.post{rv. setLoadMoreEnabled(false)} 中执行,暂时可以解决这个问题。

CxmyDev commented 3 years ago

Noting.