I want to refactor the following code so that I can reuse it with different ViewHolder types:
class TestsAdapter(
private val clickListener: ClickListener
) : PagedListAdapter<RecyclerViewTestInfo, TestsViewHolder>(diffCallback) {
override fun getItemCount(): Int {
return super.getItemCount()
}
override fun onBindViewHolder(holder: TestsViewHolder, position: Int) {
val testInfo = getItem(position) as RecyclerViewTestInfo
with(holder) {
bindTo(testInfo)
testInfo.let {
itemView.setOnClickListener {
clickListener(testInfo)
}
}
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TestsViewHolder =
TestsViewHolder(parent)
}
It isn't clear to me though how you handle the creation of an instance for a generic type. In the code, onCreateViewHolder is initialized with a specific ViewHolder. How would I do this with a generic?