I’m implementing Android
RecyclerView with three different
Adapterneeds to implement three functions, among them
fun onCreateViewHolder(parent: ViewGroup, type: Int): ViewHolderwhere the returning
ViewHoldermust be a
RecyclerView.ViewHolderor its child.
ViewHolderhas a few properties that are common for each of them. Like
Buttons. They also must have their own implementation to some common functions (mainly
bind()that will be called in
My question: how do I extract those common
- interface - cannot store state unless it’s abstract or with provided
get()implementation. But I cannot call
findViewById(R.id.widgetId)in the interface
- abstract class - cannot be instantiated, that’s problematic with requirement 1.
- class - works but it should never be instantiated, only its children.
By process of elimination, the individual
ViewHolders use both interface (abstract functions) and a class (common properties). Is there a more elegant solution?