IllegalArgumentException: Scrapped or attached views may not be recycled. isScrap:false isAttached:t

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


参考:http://www.jianshu.com/p/4fb94744f61b

     http://blog.csdn.net/u014327427/article/details/53535858

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值