‫And congratulations, guys.
‫This is our application displaying Jack as a contact from our room database.
‫But there is a problem if I run the application again with the ID equal to one, it will cause an error
‫because I'm specifying the ID and in room database.
‫It's a unique identifier, so I need to remove it and go to the contacts constructor and remove the
‫ID from here because the room database will do this job and autogenerate new contacts with the new IDs.
‫Run the program and it will solve the problem again.
‫Then I'll move to the main activity and I need to display the contacts into the recycler view.
‫So for that I need to refill this ArrayList.
‫I need to assign this contact array list in the unchanged method Contacts array list dot add C so every
‫contact in the contacts list, go and add it to the contacts array list.
‫I need to move these lines.
‫The adapter.
‫Under the ViewModel.
‫Observe Contacts.
‫Array list.
‫Let me run the application.
‫And we have this null pointer exceptions.
‫I can resolve them by changing here the contacts list, remove it and.
‫Okay.
‫I need to initialize it at first, so I'll scroll and I need to initialize a new array list.
‫Run it again.
‫And here we go.
‫This is our application.
‫It's working fine.
‫If I search for Tag and I can see the contacts.
‫So every time I run the application, it will create a new jack with a different ID and insert it into
‫our database.
‫And the most important trick here is to notify the data that recycler view with the new data.
‫So I'll use my adapter dot notify data set changed method inside ViewModel dot observe method.
‫This is the most important part here.
‫In order to display the data from logcat into the items of the recycler view, so notify data set.
‫Changed method is a method provided by recycler views adapter to notify the recycler view that are underlying
‫data has changed and the recycler view should refresh its views to reflect these changes.
‫This method is often used when you've made changes to the data resource and you need the recycler view
‫to display this change and you need to ensure that the UI is updated accordingly.
‫Let's stop the application and run it again.
‫And the Congratulations guys.
‫We succeeded in displaying the items of the recycler view from the room database.