Skip to content

Instantly share code, notes, and snippets.

@aasierra
Created July 21, 2021 13:22
Show Gist options
  • Save aasierra/10b46892e4e16fd4b78162b3a41a95b6 to your computer and use it in GitHub Desktop.
Save aasierra/10b46892e4e16fd4b78162b3a41a95b6 to your computer and use it in GitHub Desktop.
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Create the binding and set it as the content view.
val binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
// Create view model that normally would be created in an injection system such as
// by viewModel, or Dagger, or Hilt.
// For our purposes of discussion we are just instantiating here as it does not matter
// where our BusinessLogicCenter (ViewModel) comes from.
val viewModel = ProductInfoBusinessLogicCenterViewModel()
viewModel.productInfo.observe(this, { displayObject ->
// Now we simply just set the display object!
binding.displayObject = displayObject
binding.executePendingBindings()
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment