Challenge - 5 Problems
LazyGrid Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate1:30remaining
What is the visible item count in this LazyVerticalGrid?
Consider a LazyVerticalGrid with 3 columns and 10 items. Each item is a fixed size box. How many items will be visible on screen if the grid height fits exactly 4 rows?
Android Kotlin
LazyVerticalGrid(columns = GridCells.Fixed(3)) { items(10) { index -> Box(Modifier.size(100.dp)) { Text("Item $index") } } }
Attempts:
2 left
💡 Hint
Think about how many items fit in each row and how many rows fit in the visible height.
✗ Incorrect
With 3 columns and 4 rows visible, up to 3 * 4 = 12 items can be shown. Since there are only 10 items, 10 items will be visible.
❓ lifecycle
intermediate1:30remaining
When does LazyVerticalGrid compose items?
In Jetpack Compose, when does LazyVerticalGrid compose its child items?
Attempts:
2 left
💡 Hint
Lazy means it does not create all items immediately.
✗ Incorrect
LazyVerticalGrid composes only visible items plus some buffer items to optimize performance and memory.
📝 Syntax
advanced2:00remaining
Which code snippet correctly creates a LazyHorizontalGrid with 2 rows?
Select the Kotlin code that correctly creates a LazyHorizontalGrid with exactly 2 rows.
Attempts:
2 left
💡 Hint
Check the parameter name for rows in LazyHorizontalGrid.
✗ Incorrect
LazyHorizontalGrid requires the 'rows' parameter with GridCells.Fixed or GridCells.Adaptive. Option A uses correct syntax.
advanced
2:00remaining
How to preserve scroll position in LazyVerticalGrid after navigation?
You navigate away from a screen with a LazyVerticalGrid and then return. How do you preserve the scroll position of the grid?
Attempts:
2 left
💡 Hint
There is a special state class for LazyGrid scroll state.
✗ Incorrect
rememberLazyGridState() creates a state object that tracks scroll position and can be reused to restore it.
🔧 Debug
expert2:30remaining
Why does this LazyVerticalGrid crash with IllegalArgumentException?
Given this code, why does the app crash with IllegalArgumentException: 'GridCells.Fixed must be greater than 0'?
Android Kotlin
LazyVerticalGrid(columns = GridCells.Fixed(0)) { items(5) { Text("Item $it") } }
Attempts:
2 left
💡 Hint
Check the parameter passed to GridCells.Fixed carefully.
✗ Incorrect
GridCells.Fixed(0) is invalid because the number of columns must be positive. This causes the IllegalArgumentException.