Skip to content

Instantly share code, notes, and snippets.

@JosephRoskopfOPI
Last active Nov 25, 2017
Embed
What would you like to do?
public class TestViewModel extends ViewModel {
private MutableLiveData<ArrayList<User>> users;
LiveData<ArrayList<User>> returnUsers() {
if(users == null){
return fetchUsersFromNetwork();
} else {
return users;
}
}
LiveData<ArrayList<User>> fetchUsersFromNetwork() {
/**
* Network call to fetch users - once the network call returns,
* set the value using users.postValue() with the response
*/
//demo purposes - return a new array
users.postValue(new ArrayList<User>());
return users;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment