Created
June 7, 2020 11:59
-
-
Save TheBotBox/e69396b875ad2273fbd914d07c6e922b 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() { | |
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