Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
502 views
in Technique[技术] by (71.8m points)

android - UI not updating on MutableLiveData / ObservableField of List of custom objects property change with data binding

I am generating tabs in a tablayout using ObservableField of list of objects and data binding. After a certain operation I have to update the tabs. When I trying to change the property of the list item, the UI is not updating. Below is my code.

val tabsList = ObservableField<List<TabModel>>(getTabsList())

// setting the data
tabsList.get()?.first { it.isSelected }?.setPrice(price)

I have also tried MutableLiveData, and it's also not working.

Any help is appreciated.

question from:https://stackoverflow.com/questions/65925521/ui-not-updating-on-mutablelivedata-observablefield-of-list-of-custom-objects-p

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I find a solution for now. Maybe it's not the efficient way, but it is working in my scenario. Below is the code.

val updatedTabs = tabsList.get()
// setting the data
tabsList.get()?.first { it.isSelected }?.setPrice(price)
// setting a new list
tabsList.set(updatedTabs?.toList())

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...