首页 > 代码库 > XRecycleView (Scrapped or attached views may not be recycled)

XRecycleView (Scrapped or attached views may not be recycled)

这两天遇到一个问题,有个页面总是崩溃出错,错误提示是 
Process: com.eva.masterplus, PID: 3536 
java.lang.IllegalArgumentException: Scrapped or attached views may not be recycled. isScrap:false isAttached:true

是指view没有被recycled,找了半天,发现recyclerView的数据进行清空操作之后,在重新添加数据之前忘记了通知界面进行重新绘制,所以崩溃。 
解决方法只要在clear数据之后代码中记得加notifyDataSetChanged() 即可。 
还发现一种情况是在上拉加载更多或者下拉刷新之后忘记使控件重置了。要记得上拉或者下拉之后加上代码

if (swipeRefreshLayout.isRefreshing()) {
                swipeRefreshLayout.setRefreshing(false);
            } else {
                recyclerView.onLoadMoreComplete();
            }

XRecycleView (Scrapped or attached views may not be recycled)