LazyRow is a composable that displays a horizontally scrolling list. It only composes and lays out visible items, improving performance for long lists.
Click to reveal answer
beginner
How do you add spacing between items in a LazyRow?
You can add spacing by using the horizontalArrangement parameter with Arrangement.spacedBy(dp) to set space between items.
Click to reveal answer
intermediate
Why use LazyRow instead of Row for horizontal lists?
LazyRow only creates items that are visible on screen, saving memory and CPU. Row creates all items at once, which can be slow and use more memory for large lists.
Click to reveal answer
beginner
How do you handle item clicks inside a LazyRow?
You wrap each item in a clickable modifier like Modifier.clickable { /* handle click */ } to respond to user taps.
Click to reveal answer
beginner
What parameter do you use to provide the list of items to LazyRow?
You use the items function inside LazyRow's content block to pass a list and define how each item looks.
Click to reveal answer
What does LazyRow do in Jetpack Compose?
ADisplays a horizontally scrolling list with lazy loading
BDisplays a vertical list of items
CCreates all items at once in a horizontal layout
DIs used for navigation between screens
✗ Incorrect
LazyRow shows a horizontal list and only composes visible items for better performance.
val colors = listOf("Red", "Green", "Blue")
LazyRow {
items(colors) { color ->
Text(text = color)
}
}
medium
A. A vertical list showing Red, Green, Blue
B. A horizontal scrollable row showing Red, Green, Blue texts
C. An error because colors is immutable
D. Nothing, because LazyRow requires a modifier
Solution
Step 1: Analyze the code behavior
The code creates a LazyRow with items from the colors list, displaying each color as Text horizontally.
Step 2: Evaluate options
A horizontal scrollable row showing Red, Green, Blue texts correctly describes a horizontal scrollable row showing the color names. A vertical list showing Red, Green, Blue is wrong because LazyRow is horizontal, not vertical. An error because colors is immutable is wrong; immutable lists are fine. Nothing, because LazyRow requires a modifier is incorrect; modifier is optional.
Final Answer:
A horizontal scrollable row showing Red, Green, Blue texts -> Option B
C. Text composable requires named parameter for text
D. Missing parentheses in Text composable
Solution
Step 1: Check Text composable usage
Text is missing parentheses: Text item should be Text(item).
Step 2: Verify other parts
items() can accept listOf() directly, and modifier is optional.
Final Answer:
Missing parentheses in Text composable -> Option D
Quick Check:
Text(item) syntax required [OK]
Hint: Text(item) always needs parentheses [OK]
Common Mistakes:
Missing parentheses in Text(item)
Thinking items() requires modifier parameter
Assuming listOf() cannot be used inline
5. You want to create a LazyRow that shows a horizontal list of numbers from 1 to 5, but only even numbers should be displayed. Which code snippet correctly implements this?
hard
A. LazyRow { items((1..5).filter { it % 2 == 0 }) { Text(text = it.toString()) } }
B. LazyRow { items(1..5) { Text(text = it.toString()) } }
C. LazyRow { items(1..5) { Text(text = if (it % 2 == 0) it.toString() else "odd") } }
D. LazyRow { items((1..5).map { if (it % 2 == 0) it else null }) { Text(text = it.toString()) } }
Solution
Step 1: Filter the list before passing to items()
LazyRow { items((1..5).filter { it % 2 == 0 }) { Text(text = it.toString()) } } filters the range to only even numbers, so items() receives only 2 and 4.
Step 2: Check other options for correctness
LazyRow { items(1..5) { Text(text = it.toString()) } } displays all numbers 1-5. LazyRow { items(1..5) { Text(text = if (it % 2 == 0) it.toString() else "odd") } } displays 'odd' for odd numbers. LazyRow { items((1..5).map { if (it % 2 == 0) it else null }) { Text(text = it.toString()) } } maps odd numbers to null, which causes runtime errors.
Final Answer:
LazyRow { items((1..5).filter { it % 2 == 0 }) { Text(text = it.toString()) } } -> Option A
Quick Check:
Filter list before items() = LazyRow { items((1..5).filter { it % 2 == 0 }) { Text(text = it.toString()) } } [OK]
Hint: Filter list before items() to show selective items [OK]
Common Mistakes:
Forgetting the filtering condition entirely
Mapping to null causing errors
Displaying placeholder text for unwanted items
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.