Skip to content

Instantly share code, notes, and snippets.

@hiteshchopra11
Last active December 11, 2021 10:50
Show Gist options
  • Save hiteshchopra11/e7afcc2394a659549da6d7b9d7545401 to your computer and use it in GitHub Desktop.
Save hiteshchopra11/e7afcc2394a659549da6d7b9d7545401 to your computer and use it in GitHub Desktop.
val viewModel = ViewModelProvider(this)[MainActivityViewModel::class.java]
findViewById<Button>(R.id.btn_increment).setOnClickListener {
viewModel.incrementByOne()
}
viewModel.counterLiveData.observe(this) { counter ->
findViewById<TextView>(R.id.tv_counter).text = "$counter"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment