Closed Diy2210 closed 4 years ago
DONE! I refactor code. MutableLiveData:
Table Units:
Result:
But I have one more question, how implement auto add new items from ListWidget, like notifyDataSetChanged() in JAVA =)? Now to see the new entry in the list I need to restart the application.
@Diy2210 to notify changes you should use livedata's value
field to change value.
_servers.value = myNewList
and all will be updated. LiveData it's reactive data holder, all widgets subscribed to livedata and update automatically when value of livedata was changed
@Diy2210 to notify changes you should use livedata's
value
field to change value._servers.value = myNewList
and all will be updated. LiveData it's reactive data holder, all widgets subscribed to livedata and update automatically when value of livedata was changed
I do not quite understand, you can use my example plz?
My ViewModel:
ListWidget:
TableUnits:
I try add fun reload list items, but it not works:
I get it, gust add _servers.value = list to fun reload(). Now all be updated! Tnx!
fun reload() {
list = serverRepository.list()
_servers.value = list
}
Hi, I try add MutableLiveData use Database, but I don't understand how.
My List in database:
Database class:
My old MutableLiveData in ViewModelClass:
UnitItem class:
And use in ListWidget: