Let's modify this MainActivity class to complete our project. Let's start by connecting the UI to the database. We will use the RecyclerView to show the list of data from the database.
Let's create a variable of ViewModel as shown by the following code:
private lateinit var mMainViewModel: MainViewModel
Use ViewModelProviders to connect the MainViewModel with MainActivity. In onCreate(), we will get the ViewModel from the ViewModelProvider as shown by the following code:
mMainViewModel = ViewModelProviders.of(this).get(MainViewModel::class.java)
To add the LiveData observer let's add this observe() for getAllUsers() as shown by the following code:
mMainViewModel.getAllUsers().observe(this,
Observer {
userList -> userListAdapter.setNewUser(userList!!)
})