kiel
kiel copied to clipboard
how to define viewTypes with conditions
now we can register viewTypes
but README has no way to determine which viewType is created at spefici position i.e
how to make views has two types Head
, Sub
-
Head
with odd positions -
Sub
with even positions
Hi @MahmoudMabrok,
Thank you for your question.
You specify this while you are defining your RecyclerViewHolder<T>
.
You need to define HeadRecyclerViewHolder
and SubRecyclerViewHolder
for your Head
and Sub
.
In the list, which you provide the adapter, you should do that mapping.
val list = listOf("abc", "xyz", "qwe", ...)
...
// mapper
val dataSource = list.mapIndexed{index, item ->
if (index ÷ 2 == 0) Head(item) else Sub(item)
}
adapter.submitList(dataSource)
In that way, you can test your mapper.
I hope everything is clear now.
Sincerely Ibrahim
it will more better if it added with register function
Do you mean putting type in the register
function?
yes,or a way to determine type add function like register but it return viewType and with register we can select which type
i think it need brain storm to get right design
Actually type is coming by RecyclerViewHolder. As it is reified Kiel could understand which type it is.
I appreciate your support. Any syntax alternatives are welcome. also you may consider putting new syntax alternative under this issue #34.