4

I am working on a new Android project and am using the new Architecture components but could use some help in some scenarios, as I do not understand the best solution.

I have an object such as below

public class Team {

    String name;
    String location;
    List<User> users;

}

public class User {

    String firstName;
    String lastName;

}

For the ViewModel should the mutableLiveData be the Team object or each individual property, the same for the users, I will be updating and users and wonder if how I should observe those changes

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Patrick Coyne
  • 61
  • 2
  • 6
  • See this doc https://developer.android.com/topic/libraries/architecture/viewmodel – Crammeur Aug 03 '18 at 19:45
  • So if you pass a list of `User` s to a `LiveData` and make a change to some user object's property, then the observer won't be notified by the library since there isn't any change to the list rather the objects inside the list got modified but they are still the same items. You need some sort of property observing to broadcast the property changes to the observer if you're not going to do CRUD operations on the list. You could potentially deep copy an object and make changes on it and replace the original one with the copy on the list so that the observer would be notified. – insa_c Aug 03 '18 at 20:19
  • I'm working through a similar issue, right now. I'm really struggling to find a good design pattern to address this, as property observing would even then require some sort of "observeForever" on each `List` in each `Team`. as opposed to one `LiveData` that `Team` would compare to. Is there an established pattern to address this sort of need? – Mark Puchala II Feb 10 '23 at 03:59

0 Answers0