I have a very specific issue with a recyclerview + mvvm implementation.
When I select a ListItem
in the recyclerview, the click is given to my viewmodel class, which applies the "isselected" flag on the ListItem
plus the MutableLiveData
class that is observed (indirectly) by the recyclerview. This causes the observer in the mainactivity to update the whole List<ListItem>
which is displayed by the recyclerview.
The result is that whenever I select an item in the recyclerview, the recyclerview will scroll up, (presumably) because the whole list is updated, and it treats the updated list as a whole new list.
How can this behavior be adjusted in a clean code, preferably mvvm pattern.
(Maybe a solution in which the position of the click was recorded, and the new list is "scrolled" to this position immediately, if the position exists. But I don't know how to implement this, if possible.)