The observer of a LiveData List is not triggered when the order or sort of the list is changed because LiveData works based on the "identity" of the object, not the contents. In other words, if the observer is observing a LiveData List object and the contents of that object change (i.e., the items in the list are modified or re-ordered), the observer will not be notified because the object itself has not changed.
To work around this, you can create a custom LiveData object that extends the MutableLiveData class and overrides the setValue() method to compare the old and new values of the list and trigger the observer accordingly. Alternatively, you can use a different kind of observer, such as a RecyclerView.AdapterDataObserver or a PagedList.BoundaryCallback, that is specifically designed to handle changes in the contents or ordering of a list.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-06-27 13:50:02 +0000
Seen: 8 times
Last updated: Jun 27 '23