I have two RecyclerView.Adapter
s that are using exactly the same RecyclerView.ViewHolder
s as inner classes.
I wanted to get rid of code duplication and made these ViewHolder
s free, separate class so the brand new class now can be used by any RecyclerView.Adapter
s.
However I faced lots of troubles for example difficulty in accessing the adapter objects. getAdapterPosition()
always returns -1
.
So I changed my mind and made a super RecyclerView.Adapter
class which is extended by those adapters and put the ViewHolder in the superclass so those adapters can use it from subclass.
But I want to know if ViewHolder
does have to be an inner class. This makes me annoyed. Please do NOT advice me to combine the Adapter classes, they are completely different as the ViewHolder
is just a special viewType
that can be appear in any RecyclerView
I am waiting for your better approaches which make me feel better.
Regards.