I am a beginner and I would like to know that why we use ViewModel in MVVM, when we can directly access Repository and call Repository functions from Fragment. This approach seems easier. Please see below details why I ask this question.
In case you would like to see the codes, please refer below question in Stackoverflow:
Recycler view shows all data from Room database instead of just showing data of selected ids
I had a problem where I wanted to show details of a selected id in RecyclerView, but when I was using ViewModel the RecyclerView always showed the details of all ids. Then instead of accessing Repository through ViewModel, I directly accessed the Repository and solved the problem. Now the RecyclerView shows details of only the selected id.