Solution 1 :
At the end @Stachu solution works but, I have made a change by passing the value of apply block in the postValue()
like this –
user.postValue(user.value.apply{ userName = "abc" }.value)
Problem :
Suppose, I’ve a MutableLiveData<User>
. So if I update a variable in User let say userName
using the value like
var user = MutableLiveData<User>()
user.postValue(User())
user.value.userName = "ABC"
it won’t call the observer. So I have to call a postValue to invoke it.
Is there any to invoke observer after updating one property of MutableLiveData
object.
Comments
Comment posted by Shalu T D
Livedata working based on the object you specified, here it is User and based on the attributes of user object
Comment posted by stackoverflow.com/questions/48020377/…
please check this
Comment posted by Stachu
here you update the property of MutableLiveData not the User. You could do something like