0

Currently for multi-ViewHolder implementations of RecyclerView everyone suggests to have a when/switch case in onCreateViewHolder()

e.g. here: How to create RecyclerView with multiple view type?

or here: https://medium.com/@gilbertchristopher/a-recyclerview-with-multiple-view-type-22619a5ad365

I'd like to have a cleaner onCreateViewHolder() method but need a way to move this decision making code into ViewHolders themselves.

Any ideas?

Here's my adapter class for more detail in github, I'm currently doing the decision making in baseViewHolder Class : https://github.com/davida5/DavidsResume/blob/master/app/src/main/java/davids/resume/screens/resume/ResumeAdapter.kt

user158
  • 11,548
  • 7
  • 56
  • 83
David A
  • 2,112
  • 2
  • 24
  • 31
  • 1
    an argument could be made that why `abstract class SectionViewHolder` should know about its children. `ViewHolder`'s job is to bind the data to the view. Cleaner implementation would be to make a generic adapter that exposes abstract functions and the child adapter would override it and provide different implementations. Example: [generic](https://github.com/kickstarter/android-oss/blob/master/app/src/main/java/com/kickstarter/ui/adapters/KSAdapter.java), [implementation](https://github.com/kickstarter/android-oss/blob/master/app/src/main/java/com/kickstarter/ui/adapters/RewardCardAdapter.kt) – denvercoder9 Sep 06 '19 at 18:13
  • Kickstarter project seems exactly what I need, but It's very complex, I'm still trying to understand how the view is created... – David A Sep 06 '19 at 21:29
  • use [Epoxy](https://github.com/airbnb/epoxy) to deal with recyclerview multiple view types – user158 Sep 07 '19 at 02:06

0 Answers0