Dagger Multibindings for Android (Part 3)

Adriano Celentano
AndroidPub
Published in
3 min readMar 16, 2019

--

At my current project we are in the middle of implementing filters for a shopping app. We have all kinds of filters: a slider for the price, checkboxes for the gender, etc. Basically the same stuff most shopping apps have these days. The challenge here for us was, that we wanted to show different type of filters in a list and be flexible about adding or removing a filter.

While planning the feature I remembered an article by Hannes Dorfmann. He wrote about something he called Adapter Delegates. It seemed like the perfect match for our case. In this post I want to show how you can combine this pattern with multibindings, but first let’s check the basics.

When setting up an adapter for our RecyclerView we overwrite usually the following methods.

You can already see that we get a parameter viewType when creating a ViewHolder. This information is what we need to support different views in our list. The adapter knows only one viewType until we define more. To do so we need to overwrite the following method.

--

--