I have a to do list app and I have created a snackbar that shows up when a user swipes to delete an item. What I want to do is have the undo snackbar reinsert the item that was just deleted.
Here's my code that handles the swipe to delete and show snackbar
override fun onViewSwiped(position: Int) {
deleteTask(list[position].ID)
list.removeAt(position)
notifyItemRemoved(position)
updateNotesPositionInDb()
val snackbar = Snackbar.make((context as Activity).findViewById(R.id.mainLayout), "task deleted", Snackbar.LENGTH_SHORT)
snackbar.setAction("Undo") {
}
snackbar.show()
Keep in mind that this code is used in an Adapter class.