0
0
Android Kotlinmobile~10 mins

LazyColumn with items in Android Kotlin - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a LazyColumn that displays a list of names.

Android Kotlin
LazyColumn {
    items([1]) { name ->
        Text(text = name)
    }
}
Drag options to blanks, or click blank then click option'
AmutableListOf()
BarrayListOf()
ClistOf()
Dnames
Attempts:
3 left
💡 Hint
Common Mistakes
Using an empty list like listOf() instead of the actual list variable.
Forgetting to pass any list to items().
2fill in blank
medium

Complete the code to add a padding modifier of 16.dp to each Text item inside LazyColumn.

Android Kotlin
LazyColumn {
    items(names) { name ->
        Text(text = name, modifier = Modifier.[1](16.dp))
    }
}
Drag options to blanks, or click blank then click option'
Asize
Bmargin
Cpadding
DfillMaxWidth
Attempts:
3 left
💡 Hint
Common Mistakes
Using margin which does not exist in Compose.
Using size which changes the size instead of padding.
3fill in blank
hard

Fix the error in the LazyColumn code by completing the missing parameter to uniquely identify each item.

Android Kotlin
LazyColumn {
    items(items = names, key = [1]) { name ->
        Text(text = name)
    }
}
Drag options to blanks, or click blank then click option'
Anames
B{ it }
Cname
D{ index -> index }
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the whole list names as key.
Passing the variable name which is undefined in this scope.
4fill in blank
hard

Fill both blanks to create a LazyColumn that displays a list of numbers doubled.

Android Kotlin
val numbers = listOf(1, 2, 3, 4)
LazyColumn {
    items([1]) { number ->
        Text(text = (number [2] 2).toString())
    }
}
Drag options to blanks, or click blank then click option'
Anumbers
B*
C+
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition instead of multiplication.
Passing a wrong list to items.
5fill in blank
hard

Fill both blanks to create a LazyColumn that filters names longer than 3 characters and displays them in uppercase.

Android Kotlin
val names = listOf("Amy", "John", "Kate", "Bob")
LazyColumn {
    items(names.filter { it.length [1] 3 }) { name ->
        Text(text = name.[2]())
    }
}
Drag options to blanks, or click blank then click option'
A>
Buppercase
Clowercase
DtoUpperCase
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase() or toUpperCase() instead of uppercase().
Using < instead of > in the filter.