Created
June 4, 2021 10:16
-
-
Save adesamp/0d6528dec8e5d15bde7420cc34420b84 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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