'How to remain on the same position after edit or delete data from nested recycler view
I have a nested recycler view that contains parent and child adapters. I am using Room DB for showing data on the recycler view.
When I, add or delete data from a parent or child list item or parent list item, it goes to the first position.
This is how I, collect data from the view model
This is how I, collect data from Room DB and emit for activity
These are some edit delete operations executing in the activity
I just want when I, execute any operation the position remains the same not scroll for the first position. There is also a solution called the smooth Scroll To Position method but I want a solution without using this function.
Solution 1:[1]
In your collect lambda, you are setting the recyclerView's adapter every time a new flow is collected, which is making your recyclerView go on the top.
You should move binding!!.parentRecyclerView.adapter = adapter to either onCreate if using inside an activity or onViewCreated if fragment.
You can also do a null check and set only if the recycler views adapter is null. This should be avoided as it is more idiomatic to set it when the view gets created.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
