I have a Fragment, that I replace with a transaction with a new one
That Fragment contains a RecyclerView with a big number of items.
When the user presses the finish button on the new fragment I pop the backstack, and the old fragment is recreated.
This causes the OnCreateView method to be called again and everything works fine with that.
My problem is that the RecyclerView in it is recreated, the adapter is reset, but it seems to automatically move to the position that it left (which I assumed would only happen if I used transaction add not transaction replace)
As a side note the adapter still calls OnBindViewHolder and OnCreateViewHolder for the visible items.
My question is , why does this happen? since the whole fragment is recreated shouldn't it reset to the first position? Other than manually calling scrollToPosition(0) before loading the new fragment, is there another way to make the fragment not remember anything and be actually fully recreated when returning ?
The LinearLayoutManager stores the scroll position in onSaveInstanceState. Since the SavedState parcelable is stored with the view id, as long as the position is not out of bounds while returning from the backstack, the scroll position is restored.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With