how to use multiple items for different models with Model Adapter
dsantix opened this issue · 3 comments
Checklist
- [V ] Searched for similar issues
- [V ] Checked out the sample application | (principally in MultiTypeModelItemActivity.kt)
- [ V] Read the README
- [ V] Checked out the CHANGELOG
- [ V] Checked out the MIGRATION GUIDE
The file you mentioned shows the example directly under the comment:
val itemAdapter = ModelAdapter { element: IconModel ->
if (element is RightIconModel) {
RightModelIconItem(element)
} else {
ModelIconItem(element)
}
}
based on the Model
s 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.