Skip to content

Instantly share code, notes, and snippets.

@AkshayChordiya
Last active August 17, 2017 09:53
Show Gist options
  • Save AkshayChordiya/29588fdf9a13f8ff9ebbc9a57b57f495 to your computer and use it in GitHub Desktop.
Save AkshayChordiya/29588fdf9a13f8ff9ebbc9a57b57f495 to your computer and use it in GitHub Desktop.
DetailUserActivity with ViewModel - LiveData and transformations
class DetailUserActivity : LifecycleActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_detail)
// Get the ViewModel instance
val userViewModel = ViewModelProviders.of(this).get(UserViewModel::class.java)
userViewModel.setUserId(getSelectedUserId())
userViewModel.getUser().observe(this, Observer {
// Update the UI with the user details
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment