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 部署
Spring Cloud Gray 部署
2
Linux下部署ant-design-pro大小写敏感问题
Linux下部署ant-design-pro大小写敏感问题
3
The selected directory is not a valid home for Go SDK
The selected directory is not a valid home for Go SDK
4
Kubernetes api微服务开发之pod创建与删除
Kubernetes api微服务开发之pod创建与删除
5
Django POST请求报错CSRF token missing or incorrect解决
Django POST请求报错CSRF token missing or incorrect解决
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。