0
0
Android Kotlinmobile~20 mins

Swipe to dismiss in Android Kotlin - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Swipe Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2: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?
AThe item changes color but remains visible in the list.
BNothing happens; the swipe gesture is ignored.
CThe app crashes due to missing swipe callback implementation.
DThe item is removed from the adapter and disappears from the list.
Attempts:
2 left
💡 Hint
Think about what swipe to dismiss means for a list item.
lifecycle
intermediate
2: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?
AImmediately inside the onSwiped callback before notifying the adapter.
BAfter the RecyclerView animation finishes, using a delayed handler.
CNever update the data source; just hide the item visually.
DOnly when the user confirms the deletion via a dialog.
Attempts:
2 left
💡 Hint
Consider the role of onSwiped callback in ItemTouchHelper.
🔧 Debug
advanced
2: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)
}
AThe dataList is not synchronized with the adapter's data causing mismatch.
BYou must call notifyDataSetChanged() instead of notifyItemRemoved().
CThe adapterPosition changes after removal; notifyItemRemoved should use the old position before removal.
DYou forgot to override getItemCount() in the adapter.
Attempts:
2 left
💡 Hint
Think about how dataList and adapter data relate.
🧠 Conceptual
advanced
2:00remaining
How does ItemTouchHelper.Callback control swipe directions?
In ItemTouchHelper.Callback, which method controls the allowed swipe directions for items?
AonSwiped() sets the swipe direction dynamically at runtime.
BonMove() returns the swipe direction as a boolean.
CgetMovementFlags() returns flags indicating allowed drag and swipe directions.
DgetSwipeDirs() is a method to disable swipe gestures.
Attempts:
2 left
💡 Hint
Look for the method that returns flags for movement.
navigation
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?
AImmediately restore the item in onSwiped without removing it from the data source.
BShow a Snackbar with an Undo button that reinserts the item into the data and notifies the adapter.
CReload the entire RecyclerView adapter data from the database on undo.
DDisable swipe to dismiss and use a long press to delete instead.
Attempts:
2 left
💡 Hint
Think about user experience and minimal UI disruption.