Created
May 27, 2017 13:34
-
-
Save miquelbeltran/1b6760987d4b269d92cc04dfc10c9684 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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