There are tons of tutorials on how to get a simple RecyclerView going, but now my ViewHolder
logic becomes less and less simple.
Ideally I would have one instance of MyItemViewModel
per ViewHolder
, so I can separate UI related helpers. Is this at all possible?
I tried inflating and passing a binding
like this:
(in RecyclerView.Adapter.onCreateViewHolder
)
val binding = MyViewBinding.inflate(
LayoutInflater.from(parent.context), parent, false)
return MyViewHolder(binding)
But when I access binding.viewModel
in MyViewHolder.setItem(item: Item)
called via RecyclerView.Adapter.onBindViewHolder
later, it is always null
.
Any help? Can/should I instatiate one Fragment
(Activity
) per Item
/ViewHolder
so I can use ViewModelProviders
? Is there sth similar to ViewModel
that I should rather use?