Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove two items in RecyclerView instancely, the last item appear duplicated

I have a function that remove two rows of my RecyclerView (writen in Kotlin) that contain 1,2,3,4,5,6,7,8. I expect to have remain 1,4,5,6,7,8

fun remItemFromList() {
    itemList.remove(1)
    notifyItemRemoved(1)
    itemList.remove(1)
    notifyItemRemoved(1)
}

Upon execute the function, the last item i.e. double 8 appear, as per illustrated in the GIF below. Why, and how to solve this?

enter image description here

like image 775
Elye Avatar asked Nov 20 '22 18:11

Elye


1 Answers

I manage to achieve what I want using DiffUtil. More elaboration in https://medium.com/@elye.project/simultaneous-insertion-and-removal-of-recyclerview-with-animation-f9e1800a3dd0#.3evndq4is.

like image 118
Elye Avatar answered May 23 '23 17:05

Elye