Nitin Mukesh Tiwari
Nitin Mukesh Tiwari

Reputation: 81

What is the difference between Adapters such as RecyclerViewAdapter or ListAdapter and ViewModel (Architecture Component) in Android?

I am still learning the Android Programming and trying to understand the concept of ViewModel. Major motivations behind the View Models (in almost all the ViewModel tutorials) is to keep the data agnostic to LifeCycle Events. I find that Adapters used under ListView or Recyclers also offer this feature as same adapter is used by the view created in newly created Activity. I am wondering what is the exact difference between both?

As per my current understanding, ViewModel provide the ability to have lifecycle agnostic data for all the views within Activity however Adapter (though they could offer the same things) can work only on certain views. Is my understanding correct?

Upvotes: 3

Views: 1083

Answers (1)

Sagar
Sagar

Reputation: 24917

As per my current understanding, ViewModel provide the ability to have lifecycle agnostic data for all the views within Activity however Adapter (though they could offer the same things) can work only on certain views. Is my understanding correct?

Yes.

To put it in a simple way:

RecyclerViewAdapter:

Provide a binding from an app-specific data set to views that are displayed within a RecyclerView

ListAdapter:

An extended Adapter that is the bridge between a ListView and the data that backs the list

ViewModel:

Designed to store and manage UI-related data in a lifecycle conscious way. It also allows data to survive configuration changes such as screen rotations.

Upvotes: 1

Related Questions