https://kotlinlang.org logo
b

blakelee

03/03/2021, 12:16 AM
Do people pass their ViewModel into their RecyclerView adapter? I always figured that you wouldn't want to so that you can keep the adapter generic
j

Javier

03/03/2021, 12:19 AM
No
s

streetsofboston

03/03/2021, 1:36 AM
Same here: No. It is just UI. Like you said, keep it separate. The ViewModel emits a list of data that the Fragment/Activity renders as items in a RecyclerView through its Adapter. I’m not in favor of putting ViewModels into custom/aggregate Views either, for the same reason. Keep it separate. No coupling between Views and ViewModels. Let Fragments and Activities be the conduit between them.
h

Hitender Pannu

03/03/2021, 8:54 AM
Nope,
a

Amrita Chaturvedi

03/03/2021, 9:16 AM
Nope!
d

dp_singh

03/08/2021, 8:07 AM
I would suggest
passing an interface to a viewholder
that is
implemented by the viewmodel
c

Chris

03/08/2021, 8:57 AM
I saw that being done once, it's bad idea, plenty of issues, one of them is that you might want to use your adapter elsewhere with different VM. Don't know if it breaks MVVM, but it was just messy.
77 Views