Complete the code to create a LazyColumn that displays a list of names.
LazyColumn {
items([1]) { name ->
Text(text = name)
}
}The items function takes a list to display each element. Here, names is the list variable.
Complete the code to add a padding modifier of 16.dp to each Text item inside LazyColumn.
LazyColumn {
items(names) { name ->
Text(text = name, modifier = Modifier.[1](16.dp))
}
}margin which does not exist in Compose.size which changes the size instead of padding.The padding modifier adds space inside the composable's bounds. Here, 16.dp padding is added around the Text.
Fix the error in the LazyColumn code by completing the missing parameter to uniquely identify each item.
LazyColumn {
items(items = names, key = [1]) { name ->
Text(text = name)
}
}names as key.name which is undefined in this scope.The key parameter expects a lambda that returns a unique key for each item. { it } returns the item itself as the key.
Fill both blanks to create a LazyColumn that displays a list of numbers doubled.
val numbers = listOf(1, 2, 3, 4) LazyColumn { items([1]) { number -> Text(text = (number [2] 2).toString()) } }
The items function takes the numbers list. The expression number * 2 doubles each number.
Fill both blanks to create a LazyColumn that filters names longer than 3 characters and displays them in uppercase.
val names = listOf("Amy", "John", "Kate", "Bob") LazyColumn { items(names.filter { it.length [1] 3 }) { name -> Text(text = name.[2]()) } }
lowercase() or toUpperCase() instead of uppercase().< instead of > in the filter.The filter uses it.length > 3 to select names longer than 3 characters. The uppercase() function converts the name to uppercase.