What's the best way to display different items in ...
# compose-desktop
a
What's the best way to display different items in
LazyColum
? Let's say, I have
Item1
and
Item2
, I want to display one
Item2
after every 5 items of
Item1
. My initial thought, is to make them inherit a single interface and handle them based on index. But is there any other way?
m
Copy code
LazyColumn {
   repeat(10) {
      repeat(4) { 
          item { Item2() } 
      }
      item { Item1() }
   }
}
?
a
@mcpiroman I think that might do it, I haven't thought of using the
item
block. Thanks
r
I would used
sealed class
to describe the items, like
Copy code
sealed class ItemViewObject {
object Item1: ItemViewObject()
object Item2: ItemViewObject()
}
After that, passing a
List<ItemViewObjec>
to LazyColumn, where:
Copy code
LazyColumn {
items.forEach{
    when(it) {
      is Item1 -> item { /** draw item-1 */ }
      is Item2 -> item { /** draw item-2 */ }
    }
}