Skip to content

Instantly share code, notes, and snippets.

@joecks
Last active August 21, 2017 13:20
Show Gist options
  • Save joecks/d90fe41e7d2f289c89fde45da0d5b7e0 to your computer and use it in GitHub Desktop.
Save joecks/d90fe41e7d2f289c89fde45da0d5b7e0 to your computer and use it in GitHub Desktop.
// Listen to Single Event live-data object that will only report a snackbar message once
mTasksViewModel.getSnackbarMessage().observe(this, new SnackbarMessage.SnackbarObserver() {
@Override
public void onNewMessage(@StringRes int snackbarMessageResourceId) {
SnackbarUtils.showSnackbar(getView(), getString(snackbarMessageResourceId));
}
});
...
// Bind onItemClick onItemSelect to the view-model
ListView listView = mTasksFragBinding.tasksList;
mListAdapter = new TasksAdapter(
new ArrayList<Task>(0),
mTasksViewModel
);
listView.setAdapter(mListAdapter);
// bind view-model directly to the view
mTasksViewModel = TasksActivity.obtainViewModel(getActivity());
mTasksFragBinding.setViewmodel(mTasksViewModel);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment