In RecyclerView, keep element expanded / selected in config changes

90 Views Asked by At

I'm developing an Android app. I have a RecyclerView, and I can expand my items (several at the same time). The problem ocurrs when the orientation changes. I have a ViewModel, so the data is loaded again. But the items expanded are lost.

What is the best way to keep items expanded after a change of orientation?

android:configChanges="orientation" in Manifest isn't an option

1

There are 1 best solutions below

0
Rüdiger On

I would save the expanded/collapsed state to the ViewModel and then apply the saved states when a configuration change occurs.