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

在使用RecyclerView时出现问题:

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

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

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

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

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :