If I have a list inside a list and I created a vie...
# compose
r
If I have a list inside a list and I created a view like so:
Copy code
LazyColumn(modifier = modifier.fillMaxWidth()) {
   items(list1){
     it.list2.forEach{ list2Item-> 
       ItemView(list2Item)
     }
   }
 }
is this lazy column working as expected from the reusing the views point? I tried to make 2 nested lazy columns but it didn't work
b
Does this help ?
Copy code
LazyColumn(modifier = modifier.fillMaxWidth()) {
    items(list1) { listItem ->
        listItem.list2.flatten().forEach { list2Item ->
            ItemView(list2Item)
        }
    }
}
r
I just wanted to make sure that doing it this won't affect the lazy column performance
a
It surely will affect performance. You should flatten the list:
Copy code
LazyColumn(modifier = modifier.fillMaxWidth()) {
  list1.forEach {
    items(it.list2) { list2Item-> 
      ItemView(list2Item)
    }
  }
}
r
what if I wanted to have a header for each list? is this possible?
l
Of course, just add a single
item {}
in between lists.
Copy code
val listOfLists = listOf(
    "Fruits" to listOf("Apple")
)

listOfLists.forEach { (title, list) ->
    item {
        Text(title)
    }
    items(list) { item ->
        // ...
    }
}