Skip to content

Instantly share code, notes, and snippets.

@ceruleanotter
Created June 23, 2017 18:43
Show Gist options
  • Save ceruleanotter/37114c9fb26c468ced0fa13e2e9ca3d7 to your computer and use it in GitHub Desktop.
Save ceruleanotter/37114c9fb26c468ced0fa13e2e9ca3d7 to your computer and use it in GitHub Desktop.
ViewModel BlogPost : Part 1 : Step 3
// The finished onCreate method
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mViewModel = ViewModelProviders.of(this).get(ScoreViewModel.class);
displayForTeamA(mViewModel.scoreTeamA);
displayForTeamB(mViewModel.scoreTeamB);
}
// An example of both reading and writing to the ViewModel
public void addOneForTeamA(View v) {
mViewModel.scoreTeamA = mViewModel.scoreTeamA + 1;
displayForTeamA(mViewModel.scoreTeamA);
}
@hotellinawebmaster
Copy link

@ TheRedSpy15 - Good question ! I was looking for the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment