Challenge - 5 Problems
Swipe Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What happens when you swipe an item in a RecyclerView with ItemTouchHelper?
Consider a RecyclerView with an ItemTouchHelper attached to enable swipe to dismiss. What is the expected behavior when the user swipes an item fully to the left?
Attempts:
2 left
💡 Hint
Think about what swipe to dismiss means for a list item.
✗ Incorrect
Swiping an item fully triggers the removal callback, which removes the item from the adapter and updates the UI to hide it.
❓ lifecycle
intermediate2:00remaining
When should you update your data source after a swipe to dismiss?
In a swipe to dismiss implementation, when is the best time to update the underlying data source to remove the swiped item?
Attempts:
2 left
💡 Hint
Consider the role of onSwiped callback in ItemTouchHelper.
✗ Incorrect
The onSwiped callback is designed to notify you when an item is swiped. You should update your data source immediately there and notify the adapter to keep UI and data in sync.
🔧 Debug
advanced2:00remaining
Why does the app crash with IndexOutOfBoundsException after swipe to dismiss?
You implemented swipe to dismiss but after swiping an item, the app crashes with IndexOutOfBoundsException. What is the most likely cause?
Android Kotlin
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
dataList.removeAt(viewHolder.adapterPosition)
recyclerView.adapter?.notifyItemRemoved(viewHolder.adapterPosition)
}Attempts:
2 left
💡 Hint
Think about how dataList and adapter data relate.
✗ Incorrect
If the dataList used in onSwiped is not the same list the adapter uses, removing from it causes mismatch and crashes. The adapter and data source must be consistent.
🧠 Conceptual
advanced2:00remaining
How does ItemTouchHelper.Callback control swipe directions?
In ItemTouchHelper.Callback, which method controls the allowed swipe directions for items?
Attempts:
2 left
💡 Hint
Look for the method that returns flags for movement.
✗ Incorrect
getMovementFlags() returns a combination of drag and swipe directions as flags. This controls which gestures are enabled for each item.
expert
3:00remaining
What is the best way to restore a swiped item after dismissal?
After implementing swipe to dismiss, you want to allow users to undo the dismissal by restoring the item. Which approach is best?
Attempts:
2 left
💡 Hint
Think about user experience and minimal UI disruption.
✗ Incorrect
Showing a Snackbar with Undo is a common pattern. It lets users reverse the removal easily without reloading all data.