How did you achieve type safety when constructing the view holder from the view type integer?
Zak Taccardi
1

Zak Taccardi so first please don’t use an enum here but the layout id of the view. This is also what Google recommends here.

For creating the viewholders I would indeed still use a switch as its done in this repo:

https://github.com/meierjan/BetterAdapters/blob/master/app/src/main/java/wtf/meier/betteradapters/adapter/TypeFactoryForList.java

As no type casting is here it should be fine, also its hidden in the TypeFactory.

But if you want to make it a bit more fancy you could even there use the visitor pattern and have createHolder interface similar to the type one.

Like what you read? Give Danny Preussler a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.