Android MVVM: Where to put adapters?-ThrowExceptions

Exception or error:

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?

How to solve:

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

###

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

###

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.

Leave a Reply

Your email address will not be published. Required fields are marked *