I have two RecyclerView.Adapter that use the same RecyclerView.ViewHolder as inner classes.
I wanted to get rid of code duplication and made this ViewHolder free, separate class, so the new class can now be used by any RecyclerView.Adapter s.
However, I encountered many problems, for example, difficulties in accessing adapter objects. getAdapterPosition() always returns -1 .
So, I changed my mind and made a super RecyclerView.Adapter class that extends these adapters and puts the ViewHolder in a superclass so that these adapters can use it from a subclass.
But I want to know if ViewHolder should be an inner class. It annoys me. Please DO NOT advise me to combine adapter classes, they are completely different, since ViewHolder is just a special viewType that can appear in any RecyclerView
I look forward to your best approaches that make me feel better.
Sincerely.
java android android-recyclerview android-viewholder
Egemen hamutรงu
source share