Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android MVVM: Where to put adapters?

Tags:

android

mvvm

I'm building an Android app following the MVVM architecture. Where do adapters (for recyclerView, viewPager, etc) belong to?

Do adapters belong to View or ViewModel?

like image 686
iori24 Avatar asked Oct 05 '17 06:10

iori24


People also ask

Should I pass ViewModel to adapter?

Warning: It's bad practice to pass the ViewModel into the RecyclerView adapter because that tightly couples the adapter with the ViewModel class.

What is the use of adapters in Android Studio?

An Adapter object acts as a bridge between an AdapterView and the underlying data for that view. The Adapter provides access to the data items. The Adapter is also responsible for making a View for each item in the data set.

Why MVVM is better than MVP in Android?

MVVM is better than MVC/MVP because of its unidirectional data and dependency flow. Dependency is one way, thus it is a lot easier to decouple it when we need to. It is also easier for testing. All my projects(written in Kotlin for Android app) are based on MVVM.

What are adapters in Android?

In Android, Adapter is a bridge between UI component and data source that helps us to fill data in UI component. It holds the data and send the data to an Adapter view then view can takes the data from the adapter view and shows the data on different views like as ListView, GridView, Spinner etc.


1 Answers

Adapter belongs to View, but data source of Adapter belongs to ViewModel.

like image 118
Nikolay Avatar answered Sep 30 '22 09:09

Nikolay