adrianfc
5/8/2020 - 1:23 PM

SetUpViewModel

private lateinit var binding: ActivityMainBinding
private lateinit var viewModel: MainViewModel

binding = DataBindingUtil.setContentView(this, R.layout.activity_main)

// Get the viewmodel
viewModel = ViewModelProviders.of(this).get(MainViewModel::class.java)

// Set the viewmodel for databinding - this allows the bound layout access to all of the
// data in the VieWModel
binding.mainViewModel = viewModel

// Specify the current activity as the lifecycle owner of the binding. This is used so that
// the binding can observe LiveData updates
binding.setLifecycleOwner(this)