Alexander Suraphel
07/18/2021, 4:46 PMLazyColumn(modifier = modifier) {
for (name in names) {
Greeting(name = name)
Divider(color = Color.Black)
}
}
Peter Mandeljc
07/18/2021, 4:46 PMPeter Mandeljc
07/18/2021, 4:46 PMAlexander Suraphel
07/18/2021, 4:47 PMAlexander Suraphel
07/18/2021, 4:47 PMLazyColumn(modifier = modifier) {
items(items = names) { name ->
Greeting(name = name)
Divider(color = Color.Black)
}
}
Peter Mandeljc
07/18/2021, 4:47 PMAlexander Suraphel
07/18/2021, 4:47 PMPeter Mandeljc
07/18/2021, 4:47 PMAlexander Suraphel
07/18/2021, 4:47 PMAlexander Suraphel
07/18/2021, 4:47 PMAlexander Suraphel
07/18/2021, 4:49 PMAlexander Suraphel
07/18/2021, 4:49 PMPeter Mandeljc
07/18/2021, 4:49 PMAlexander Suraphel
07/18/2021, 4:49 PMAlexander Suraphel
07/18/2021, 4:51 PMAlexander Suraphel
07/18/2021, 4:51 PMitems(items = names) { name ->
Greeting(name = name)
Divider(color = Color.Black)
}
Alexander Suraphel
07/18/2021, 4:51 PMAlexander Suraphel
07/18/2021, 4:51 PMAlexander Suraphel
07/18/2021, 4:52 PMCLOVIS
07/18/2021, 5:01 PMfor (name in names)
, you are going through all the names
(standard Kotlin syntax), which means you are trying to display all of the names. That's fine for Column, but LazyColumn doesn't want all names, it just wants the ones visible on screen. By using the items
function (specific to Compose), you are telling LazyColumn how to compute a single item, and Compose will then use that multiple times on just the items that are on screen.Alexander Suraphel
07/18/2021, 5:02 PMAlexander Suraphel
07/18/2021, 5:03 PMCLOVIS
07/18/2021, 5:06 PMAlexander Suraphel
07/18/2021, 5:25 PM