I\'m using a simple implementation of RecyclerView
taken from the Android website using a StaggeredGridLayoutManager
and I keep getting this error
I met this issue this morning, but I am not facing the same reason as mentioned above.
Via debug I found that the item view in my ViewHolder has mParent
and it's not null, which in normal case it should be none( that's what the log saying, "attached view may not be recycled", I think it means that if the child view is already attached to a parent, it would some how cause failure when recyclering.)
But I didn't attach the child view every time manually. And I found that it's done when I try to inflate the child view in my ViewHolder, something like:
layoutInflater.inflate(@LayoutRes int resource, @Nullable ViewGroup root, boolean attachToRoot)
And the last parameter attachToRoot
should be false.
After I change it to false
, I fixed my problem.
By the way, I only see this crash happened when I upgrade my support library to latest version 25.0.0. Before I was using version 23.4.0 and I don't see this problem happening. I guess there should be something changed in the latest support library.
Hope this help.