https://kotlinlang.org logo
#compose
Title
# compose
a

Arpit Shukla

11/23/2021, 4:16 AM
I have a data class like this:
Copy code
data class Category (
    val title: String,
    val items: List<String>
)
And I want to display a list of
Category
using a LazyColumn. I tried this:
Copy code
LazyColumn {
    items(list) { category ->
        Text(text = category.title)
        category.items.forEach { item ->
            Text(text = item)
        }
    }
}
But I want to replace the inner loop with something lazy. I can't nest another LazyColumn. Using
this@LazyColumn.items(category.items)
doesn't give the desired UI. How to implement this case?
a

Albert Chang

11/23/2021, 4:19 AM
Copy code
LazyColumn {
    list.forEach { category ->
        item {
            Text(text = category.title)
        }
        items(category.items) { item ->
            Text(text = item)
        }
    }
}
a

Arpit Shukla

11/23/2021, 4:22 AM
It worked. Thanks !!!
👍 1
3 Views