So I have a LiveData RVA (Recycler View Adapter), along with an ArrayList()
, all of which are MutableLiveData
. However, I need to let the RVA know when the ArrayList()
's are updating, so I need to call notifyItemInserted
, notifyItemRangeDeleted
, etc. However, when I set multiple Observer
s to observe the RVA in order to perform the following, since they all had the same owner (a fragment), all the observers would be notified when I needed only 1.
For example, if I added 1 element to ArrayList()
:
Expected: RVA calls notifyItemInserted
through 1 observer
What Happened RVA calls a bunch of different methods through multiple observers
I don't think this is the right way to update a MutableLiveData
RVA, but I don't know any other way. Unlike the ArrayList()
, where you can just use setValue
to update it, RVA has methods that I can't call without alerting a bunch of other methods.
One way I thought about was implementing a for loop to check what modification the ArrayList()
was receiving and then relaying that to the RVA so it could use the correct notify....()
. But I feel like that would be inefficient, especially since the user is updating the ArrayList()
quite often.