0

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 Observers 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.

Soil Milk
  • 3
  • 1
  • Your question lacks a supporting code. Try adding some supporting code in a [minimal reproducible](https://stackoverflow.com/help/minimal-reproducible-example) form. This helps us to understand and figure out your problem better. – Kozmotronik Jun 16 '23 at 06:04

0 Answers0