Recyclerview Crashes When "scrapped Or Attached Views May Not Be Recycled"
Solution 1:
This error is caused if in your XML you have android:animateLayoutChanges
set to true and you call notifyDataSetChanged()
on the RecyclerView's adapter in the Java code.
So, just avoid using android:animateLayoutChanges
with RecyclerViews.
Solution 2:
I've had to deal with this crash also and in my case it had nothing to do with android:animateLayoutChanges
.
The RecyclerView
we were building had more than one type of views in it and some were having EditText
s in them. After a while we pinned the issue to being focus related. This bug happens while recycling EditText
s and one of them is focused.
Naturally we tried clearing the focus when new data is being bound to a recycled view but that didn't work until android:focusableInTouchMode="true"
is set on RecycleView
. Actually that is the only change that was needed in the end for this issue to go away.
Solution 3:
I removed the android:animateLayoutChanges
from layout property and problem has been resolved.
Solution 4:
Among the reasons that anyone can face this issue, check if you have set the attribute android:animateLayoutChanges="true"
to the RecyclerView. This will cause the recycling and reattaching the RecyclerView's items to fail. Remove it and assign the attribute to the RecyclerView's parent container, such as a LinearLayout/RelativeLayout and you should see the problem go away.
Solution 5:
It took me two days but could not get around this, in the end, I had to disable the item prefetch.
When setting the layout manager you can simply call
mGridLayoutManager.setItemPrefetchEnabled(false);
It made the error go away for me. Hope it will be useful for someone.
Post a Comment for "Recyclerview Crashes When "scrapped Or Attached Views May Not Be Recycled""