I have a pretty straightforward question about LiveData. I have a MutableLiveData<MutableList<Car>>
and I want to update a specific field in my list, so I guess that when the field is updated, the MutableLiveData should trigger the observers but that does not happen.
So if I use this line of code my observers are not triggered.
var carList = MutableLiveData<MutableList<Car>>()
...
carList.value?.set(car.id,Car(car.id, color))
But if I do something like this the observers are triggered.
var carList = MutableLiveData<MutableList<Car>>()
...
var newList = carList.value
carList?.set(car.id,Car(car.id, color))
carList.value = newList
Can please somebody explain why this happens? Is it essential to give a whole new list to the livedata to be triggered or there is something I am missing? Thank you in advance.