Skip to content

Instantly share code, notes, and snippets.

@miquelbeltran
Created May 27, 2017 13:34
Show Gist options
  • Select an option

  • Save miquelbeltran/1b6760987d4b269d92cc04dfc10c9684 to your computer and use it in GitHub Desktop.

Select an option

Save miquelbeltran/1b6760987d4b269d92cc04dfc10c9684 to your computer and use it in GitHub Desktop.
// As class member
private BooksViewModel model;
@Override
protected void onCreate(Bundle savedInstanceState) {
// Rest of method removed from example
// Load our BooksViewModel or create a new one
model = ViewModelProviders.of(this).get(BooksViewModel.class);
// Listen for changes on the BooksViewModel
model.getBooks().observe(this, new Observer<List<Book>>() {
@Override
public void onChanged(@Nullable List<Book> books) {
// Called each time the BooksViewModel.books content changes
updateUi(books);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment