Skip to content

Instantly share code, notes, and snippets.

@gonzalonm
Last active October 5, 2017 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gonzalonm/f31560b83d56abe1b5e0e6003fd8d9f1 to your computer and use it in GitHub Desktop.
Save gonzalonm/f31560b83d56abe1b5e0e6003fd8d9f1 to your computer and use it in GitHub Desktop.
public class MyViewModel extends ViewModel {
private MutableLiveData<List<Article>> articles;
public LiveData<List<Article>> getArticles() {
if (articles == null) {
articles = new MutableLiveData<List<Article>>();
loadArticles();
}
return articles;
}
private void loadArticles() {
// do async operation to fetch articles
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment