Skip to content

Instantly share code, notes, and snippets.

@fluxtah
Last active February 19, 2020 14:33
Show Gist options
  • Save fluxtah/989119242c1a25e35ae232f684c368fc to your computer and use it in GitHub Desktop.
Save fluxtah/989119242c1a25e35ae232f684c368fc to your computer and use it in GitHub Desktop.
class MyViewModel : BaseViewModel() {
val data: LiveData<String> = MutableLiveData()
fun load() {
data.value = "Hello, World"
}
}
class MyActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val vm = ViewModelProviders.of(this).get(MyViewModel::class.java)
vm.data.observe(this, Observer {
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