Skip to content

Instantly share code, notes, and snippets.

@tpakis
Created April 27, 2018 12:58
Show Gist options
  • Save tpakis/c68f24ac7a09d3d15d718a1eb2466672 to your computer and use it in GitHub Desktop.
Save tpakis/c68f24ac7a09d3d15d718a1eb2466672 to your computer and use it in GitHub Desktop.
//couple the activity with the view model
viewModel = ViewModelProviders.of(this).get(MainActivityViewModel.class);
//subscribe to LiveData
viewModel.getRecipesListObservable().observe(MainActivity.this, new Observer<Resource<List<Recipe>>>() {
@Override
public void onChanged(@Nullable Resource<List<Recipe>> recipes) {
Timber.d(recipes.status.toString());
}
});
//ask the viewmodel for data (maybe an event happened?or onCreate?)
viewModel.getData();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment