mikepenz/FastAdapter

how to use multiple items for different models with Model Adapter

dsantix opened this issue · 3 comments

Checklist

The file you mentioned shows the example directly under the comment:

https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/MultiTypeModelItemActivity.kt#L37-L43

val itemAdapter = ModelAdapter { element: IconModel ->
            if (element is RightIconModel) {
                RightModelIconItem(element)
            } else {
                ModelIconItem(element)
            }
        }

based on the Models type a different item will be used

I see, but in the example RightModelIconItem and ModelIconItem use the same IconModel.
In my case I use a Header that has the Model different from ItemA and ItemB.

I want something like:

  • Header
  • Item A
  • Header
  • Item B

Am I using it the wrong way?

In the sample both have a base class IconModel but one is of type RightIconModel, as you can see in the type check.

Do you want your headers to be sticky or stay as part of the list? (Sticky headers are not part of this library, as this is usually handled by decorators or such) -> there's one sample activity in the sample app using an external library

for your order. you can surely achieve this either by having different model types (and in any case the top parent type could by Any if nothing else common applies) and then map to the target items you expect.

In case you do not want to split Model and Item you can also achieve this.