Bird
Raised Fist0
Android Kotlinmobile~20 mins

Card composable in Android Kotlin - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Card Composable Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate
2:00remaining
What is the visual output of this Card composable code?
Consider this Kotlin Compose code snippet for a Card. What will the user see on the screen?
Android Kotlin
Card(
  modifier = Modifier.size(100.dp),
  elevation = 8.dp
) {
  Text("Hello Card", modifier = Modifier.padding(16.dp))
}
AA plain text 'Hello Card' without any card background or shadow
BA card with no shadow and no padding around the text
CA card with a shadow and the text 'Hello Card' inside with padding
DAn empty card with no visible content
Attempts:
2 left
💡 Hint
Remember that Card adds elevation by default and the Text has padding inside the card.
❓ lifecycle
intermediate
2:00remaining
What happens when you update the state inside a Card composable?
If you have a Card composable displaying a counter and you update the counter state, what happens to the Card UI?
Android Kotlin
var count by remember { mutableStateOf(0) }
Card {
  Text("Count: $count")
}
// On button click: count++
AThe Card recomposes and updates the displayed count immediately
BThe Card does not update until the whole screen is refreshed
CThe Card crashes because state cannot be used inside Card
DThe Card UI freezes and does not show the updated count
Attempts:
2 left
💡 Hint
Compose automatically updates UI when state changes inside composables.
📝 Syntax
advanced
2:00remaining
Which option correctly sets a rounded corner shape on a Card?
You want to create a Card with rounded corners of 12.dp radius. Which code snippet does this correctly?
ACard(shape = RoundedCornerShape(12.dp)) { Text("Rounded Card") }
BCard(cornerRadius = 12.dp) { Text("Rounded Card") }
CCard(shape = CornerRadius(12.dp)) { Text("Rounded Card") }
DCard(borderRadius = 12.dp) { Text("Rounded Card") }
Attempts:
2 left
💡 Hint
Look for the correct parameter name and type for shape in Card composable.
❓ navigation
advanced
2:00remaining
How to navigate to a new screen when a Card is clicked?
You want to navigate to a DetailScreen when the user taps on a Card. Which approach correctly handles this?
Android Kotlin
Card(modifier = Modifier.clickable { /* navigate */ }) {
  Text("Go to Details")
}
ASet a click listener on Text inside the Card to navigate
BWrap Card inside a Button composable and use onClick to navigate
CUse Card's onClick parameter to call navController.navigate("detail")
DUse Modifier.clickable with a lambda calling navController.navigate("detail") inside the Card
Attempts:
2 left
💡 Hint
Card itself does not have an onClick parameter; use Modifier.clickable instead.
🔧 Debug
expert
2:00remaining
Why does this Card not show elevation shadow?
This Card composable code does not show any shadow even though elevation is set. What is the cause?
Android Kotlin
Card(
  modifier = Modifier.size(100.dp),
  elevation = 8.dp,
  backgroundColor = Color.Transparent
) {
  Text("No Shadow")
}
AElevation must be set using shadow() modifier, not elevation parameter
BSetting backgroundColor to Transparent removes the shadow effect
CCard requires a border to show elevation shadow
DText inside Card must have padding to show shadow
Attempts:
2 left
💡 Hint
Think about how transparent backgrounds affect shadows in Compose.

Practice

(1/5)
1. What is the primary purpose of using a Card composable in Android Jetpack Compose?
easy
A. To group related content visually with padding, shadow, and shape
B. To create a button with click actions
C. To display a list of items vertically
D. To handle navigation between screens

Solution

  1. Step 1: Understand the role of Card composable

    The Card composable is designed to group related UI elements visually by adding padding, shadows, and rounded corners.
  2. Step 2: Differentiate from other composables

    Buttons handle clicks, lists display multiple items, and navigation manages screen changes, which are not the primary roles of Card.
  3. Final Answer:

    To group related content visually with padding, shadow, and shape -> Option A
  4. Quick Check:

    Card groups content visually = A [OK]
Hint: Cards group content visually with style and padding [OK]
Common Mistakes:
  • Confusing Card with Button composable
  • Thinking Card manages navigation
  • Assuming Card is for lists only
2. Which of the following is the correct syntax to create a simple Card with padding in Jetpack Compose?
easy
A. Card(modifier = Modifier.padding(16.dp)) { Text("Hello") }
B. Card(padding = 16.dp) { Text("Hello") }
C. Card { modifier = Modifier.padding(16.dp); Text("Hello") }
D. Card(Modifier.padding(16)) { Text("Hello") }

Solution

  1. Step 1: Check correct use of Modifier and padding

    Modifier.padding(16.dp) is the correct way to add padding to a composable in Jetpack Compose.
  2. Step 2: Validate syntax correctness

    Card(modifier = Modifier.padding(16.dp)) { Text("Hello") } correctly passes modifier = Modifier.padding(16.dp) to Card. Other options misuse parameters or omit .dp unit.
  3. Final Answer:

    Card(modifier = Modifier.padding(16.dp)) { Text("Hello") } -> Option A
  4. Quick Check:

    Modifier.padding(16.dp) syntax = D [OK]
Hint: Use modifier = Modifier.padding(16.dp) inside Card [OK]
Common Mistakes:
  • Using padding parameter directly on Card
  • Forgetting .dp unit for padding
  • Assigning modifier inside Card content block
3. What will be the visual result of this code snippet?
Card(modifier = Modifier.padding(8.dp)) {
  Text("Welcome", modifier = Modifier.padding(16.dp))
}
medium
A. A card with no padding and text padded by 8.dp
B. Text "Welcome" without padding inside a card with 8.dp padding
C. A card with "Welcome" text padded inside and card itself padded from outside
D. A card with 16.dp padding and text with 8.dp padding

Solution

  1. Step 1: Analyze Card modifier padding

    The Card has Modifier.padding(8.dp), so the card itself is spaced 8.dp from surrounding elements.
  2. Step 2: Analyze Text modifier padding

    The Text inside the Card has Modifier.padding(16.dp), so the text is padded inside the card by 16.dp.
  3. Final Answer:

    A card with "Welcome" text padded inside and card itself padded from outside -> Option C
  4. Quick Check:

    Card padding outside + Text padding inside = C [OK]
Hint: Card padding affects outside space; Text padding affects inside space [OK]
Common Mistakes:
  • Confusing which padding applies to card vs text
  • Assuming padding stacks add up inside
  • Ignoring modifier order effects
4. Identify the error in this Card composable code:
Card(modifier = Modifier.padding(12)) {
  Text("Error example")
}
medium
A. Text composable cannot be inside Card
B. Missing .dp unit for padding value
C. Modifier.padding cannot be used with Card
D. Card requires a background color parameter

Solution

  1. Step 1: Check Modifier.padding parameter

    Modifier.padding requires a Dp value like 12.dp, not just 12.
  2. Step 2: Validate other parts

    Text inside Card is valid, Modifier.padding works with Card, and background color is optional.
  3. Final Answer:

    Missing .dp unit for padding value -> Option B
  4. Quick Check:

    Modifier.padding needs .dp unit = B [OK]
Hint: Always add .dp after numeric padding values [OK]
Common Mistakes:
  • Omitting .dp unit causes compile error
  • Thinking Card needs background color always
  • Believing Text can't be child of Card
5. You want to create a Card that has rounded corners, a shadow, and changes background color when clicked. Which approach correctly combines these features?
hard
A. Use Card with elevation for corners, shape for shadow, and no clickable modifier
B. Use Card with padding for shadow, shape for color, and clickable for corners
C. Use Card with background color parameter only and add shadow manually
D. Use Card with shape = RoundedCornerShape(12.dp), elevation = 8.dp, and clickable modifier with background color change inside

Solution

  1. Step 1: Understand Card parameters for style

    RoundedCornerShape sets corners, elevation adds shadow, and clickable modifier handles clicks.
  2. Step 2: Combine clickable with background color change

    Clickable modifier can be used with state to change background color on click inside Card content.
  3. Step 3: Evaluate options

    Use Card with shape = RoundedCornerShape(12.dp), elevation = 8.dp, and clickable modifier with background color change inside correctly uses shape, elevation, and clickable with background color change. Others misuse parameters or miss features.
  4. Final Answer:

    Use Card with shape = RoundedCornerShape(12.dp), elevation = 8.dp, and clickable modifier with background color change inside -> Option D
  5. Quick Check:

    Shape + elevation + clickable for color change = A [OK]
Hint: Combine shape, elevation, and clickable modifier for interactive Card [OK]
Common Mistakes:
  • Confusing elevation with padding for shadow
  • Misusing shape for background color
  • Forgetting clickable modifier for interaction
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard