recyclerview刷新崩溃,报错log:
java.lang.IllegalArgumentException: Scrapped or attached views may not be recycled. isScrap:false isAttached:true at android.support.v7.widget.RecyclerView$Recycler.recycleViewHolderInternal(RecyclerView.java:5736) at android.support.v7.widget.RecyclerView$Recycler.quickRecycleScrapView(RecyclerView.java:5843) at android.support.v7.widget.RecyclerView$LayoutManager.removeAndRecycleScrapInt(RecyclerView.java:8501) at android.support.v7.widget.RecyclerView.dispatchLayoutStep3(RecyclerView.java:3656) at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3323) at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3844) at android.view.View.layout(View.java:15697) at android.view.ViewGroup.layout(ViewGroup.java:5050) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557) at android.widget.LinearLayout.onLayout(LinearLayout.java:1466) at android.view.View.layout(View.java:15697) at android.view.ViewGroup.layout(ViewGroup.java:5050) at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1193) at android.view.View.layout(View.java:15697) at android.view.ViewGroup.layout(ViewGroup.java:5050) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579) at android.widget.FrameLayout.onLayout(FrameLayout.java:514)APP测试的时候,遇到recyclerview刷新崩溃,百度发现很多人都遇到了这个问题,然后在别人的基础上我自己做个小总结,若有错误的,欢迎大家评论指正。
1.xml使用android:animateLayoutChanges="true",并且recyclerview刷新调用了notifydatasetchanged
解决:android:animateLayoutChanges="true"与RecyclerView的刷新不可同时存在
2.recyclerview刷新清空数据,未调用notifyDataSetChanged(),或者是在请求数据之前就先clear数据了,然后请求之后才notifyDataSetChanged()
解决:获取到数据之后再清空旧的数据,然后再添加新的数据,再adapter.notifydatasetchanged