iadcialim24
iadcialim24

Reputation: 4035

Android MVVM: Where to put adapters?

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?

Upvotes: 33

Views: 13895

Answers (3)

Tejas Pandya
Tejas Pandya

Reputation: 4087

If you're following MVVM architecture than , adapters are belongs to View not Viewmodel. All sub list item click events and other UI related things handled by adapter . So Adapter goes to View ..

if you want detail description , You can check this link to

MVVM Detail

Upvotes: 8

Ashutoshg
Ashutoshg

Reputation: 157

Think on this direction.. Suppose you remove/replace your view from your code. View model should be able to reused again and can provide view data to new view. You can get answer yourself. Then adapter should be part of view only.

Upvotes: 5

Nikolay
Nikolay

Reputation: 1448

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

Upvotes: 44

Related Questions