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();
}
上一篇 Android TextView及布局Layout设置selector
下一篇 解决strings.xml格式化占位符错误:Multiple substitutions specified in non-positional format
目录
文章列表
1 Spring Cloud Gray 3.0 灰度解决方案
Spring Cloud Gray 3.0 灰度解决方案
2
Flutter实现Toast效果
Flutter实现Toast效果
3
微信小程序数据绑定保留小数位数
微信小程序数据绑定保留小数位数
4
CentOS下Nginx及PHP快速安装
CentOS下Nginx及PHP快速安装
5
Swift UI - 图像控件(UIImageView)
Swift UI - 图像控件(UIImageView)
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。