Skip to content

Instantly share code, notes, and snippets.

@TheBotBox
Created June 7, 2020 11:59
Show Gist options
  • Save TheBotBox/e69396b875ad2273fbd914d07c6e922b to your computer and use it in GitHub Desktop.
Save TheBotBox/e69396b875ad2273fbd914d07c6e922b to your computer and use it in GitHub Desktop.
class MainActivity : AppCompatActivity() {
private val mBinding by viewBinding(ActivityMainBinding::inflate)
private val mViewModel by viewModel<MainViewModel>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(mBinding.root)
mBinding.viewModel = mViewModel
mViewModel.fetchRandomQuoteLiveData.observe(this, Observer { // observing response from viewmodel
mBinding.quote.text = "${it.quote} \n\n-${it.author} \n\nid:${it.quote_id}"
})
mViewModel.errorLiveData.observe(this, Observer { // observing exception message from viewmodel
Toast.makeText(this, it, Toast.LENGTH_SHORT).show()
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment