Android Cannot call this method while RecyclerView is computing a layout or scrolling

在使用RecyclerView时出现问题:

java.lang.IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling

出错原因:非法状态异常,即当RecyclerView在计算布局,或者在滑动的时候,不能调用notifyDataSetChanged

解决方法:在RecyclerView滑动或者计算layout的时候不刷新数据

if (mRecyclerView.getScrollState() == RecyclerView.SCROLL_STATE_IDLE && (!mRecyclerView.isComputingLayout())) {
    mAdapter.notifyDataSetChanged();
}

版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/02/26/android-cannot-call-this-method-while-recyclerview-is-computing-a-layout-or-scrolling/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
打赏
海报
Android Cannot call this method while RecyclerView is computing a layout or scrolling
在使用RecyclerView时出现问题: java.lang.IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling 出错……
<<上一篇
下一篇>>
文章目录
关闭
目 录