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 Android P 适配踩坑记录
Android P 适配踩坑记录
2
AWS EC2实例附加的ASG迁移操作
AWS EC2实例附加的ASG迁移操作
3
Gitlab SMTP发送邮件报错 Net OpenTimeout execution expired
Gitlab SMTP发送邮件报错 Net OpenTimeout execution expired
4
Spring Cloud Gateway 熔断、降级、限流
Spring Cloud Gateway 熔断、降级、限流
5
Linux平台编译Android报错aapt2 /lib64/libc.so.6 version 'GLIBC_2.14' not found
Linux平台编译Android报错aapt2 /lib64/libc.so.6 version 'GLIBC_2.14' not found
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。