Skip to content

Instantly share code, notes, and snippets.

@aasierra
Created July 21, 2021 13:12
Show Gist options
  • Save aasierra/56ef21ab430983bdb9eadb27a8ecee21 to your computer and use it in GitHub Desktop.
Save aasierra/56ef21ab430983bdb9eadb27a8ecee21 to your computer and use it in GitHub Desktop.
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// 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 ->
// Using kotlin synthetics we simply set the text.
productName.text = displayObject.productName
price.text = displayObject.price
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment