Tmp detached view should be removed from RecyclerView before it can be recycled
See original GitHub issueHi. I’m getting some random crashes in one particular screen of my app. The screen is a scrolling view of various movie details, and I use Epoxy to create it. This is the error reported in logcat:
java.lang.IllegalArgumentException: Tmp detached view should be removed from RecyclerView before it can be recycled
A complete stack trace can be found here
Some Googling suggest the following solutions:
- Setting 'setHasStableIds = false` on the recycler view adapter but this option obviously does not apply to Epoxy. source
- Removing custom item animators on the RecyclerView, but I’m not using any. source
Here’s the Epoxy Model for which this error occurs:
@EpoxyModelClass(layout = R.layout.view_info_text)
abstract class InfoTextModel : EpoxyModelWithHolder<InfoTextModel.InfoTextViewHolder>() {
@EpoxyAttribute
lateinit var text: String
override fun bind(holder: InfoTextViewHolder) {
super.bind(holder)
holder.textView.text = text
}
inner class InfoTextViewHolder : KotlinEpoxyHolder() {
val textView by bind<TextView>(R.id.tvInfoText)
}
}
Here’s the XML file for this model:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tvInfoText"
style="@style/TextAppearance.MaterialComponents.Body2.EmptyViewTextStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="100dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:layout_gravity="center"
android:gravity="center"/>
</FrameLayout>
Here’s the relevant code in the Epoxy Controller:
actorsList.takeIf { list -> !list.isNullOrEmpty() }?.forEach { actorResource ->
...
} ?: infoText {
id("cast-empty")
text("This list seems to be empty")
spanSizeOverride { totalSpanCount, _, _ -> totalSpanCount }
}
If you need complete sources, they can be found in this package on my Github repo
I’m not sure why does this error occur, or how to solve it. This seems to be a recycler view specific issue, but in my app I’m using the EpoxyRecyclerView
class.
Any help would be greatly appreciated.
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (2 by maintainers)
I was also getting bugged by this issue in production, turns out you shouldn’t use
android:animateLayoutChanges="true"
on the parent ViewGroup of the RecyclerView/EpoxyRecyclerViewAfter I removed that one line, everything runs like a peach!
This issue is quite known: https://stackoverflow.com/a/60024405/878126
I reported about this here: https://issuetracker.google.com/issues/148720682
Basically I think it’s RecyclerView not liking that you hide it while it’s still animating.