If you are using ListAdapter, what will you do when you want to change a property of model and notify file UI change?
For example: when tapping an item change it ’s background
Mine way: I’m will submit new list to adapter but not enough, it change the model in current list but UI not change yet, so I need to make model extend from
BaseObservable
and call
notifyChange
function
😶 1
j
Josh Yun
02/08/2022, 10:06 AM
If you mean ListAdapter for RecyclerView and if you are using DiffUtil.ItemCallback, then check your comparison functions. If the callback’s methods can detect data change correctly, submitting new list will just update the UI.
t
Thanh Vu
02/08/2022, 10:13 AM
I did it but it not working, in
areContentsTheSame
function, I have compared every model properties
j
Josh Yun
02/08/2022, 10:19 AM
Is your model’s properties primitives or data classes? or try submitting new list by calling list.toList() or list.toMutableList()
t
Thanh Vu
02/08/2022, 10:22 AM
My model properties is primitive and when I submit new list I do this
submitList(ArrayList(newList))
o
Orhan Tozan
02/09/2022, 11:07 AM
@Thanh Vu if you show us your code I can maybe help