Skip to content

Instantly share code, notes, and snippets.

@adesamp
Created June 4, 2021 10:16
Show Gist options
  • Save adesamp/0d6528dec8e5d15bde7420cc34420b84 to your computer and use it in GitHub Desktop.
Save adesamp/0d6528dec8e5d15bde7420cc34420b84 to your computer and use it in GitHub Desktop.
class MainActivity : AppCompatActivity() {
// initialize view model, in this case using koin extension
private val viewModel: MainViewModel by viewModel()
// observe value
viewModel.name.observe(this, ::setName)
private fun setName(name: String?) = binding.edtName.setText(name)
// fetch data on the first time / activtity created
viewModel.fetch()
// save name when button clicked
viewModel.saveName(name)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment