João Sardinha João Sardinha - 3 months ago 40
Java Question

RecyclerView: last item's animation on notifyItemRemoved()

Behaviour's video: https://vid.me/nF1J

Removing:

viewHolder.buttonDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mItemManger.removeShownLayouts(viewHolder.swipeLayout);
mDataset.remove(position);
notifyItemRemoved(position);
notifyItemRangeChanged(position, mDataset.size());
mItemManger.closeAllItems();
Toast.makeText(view.getContext(), "Deleted " + viewHolder.textViewPos.getText().toString() + "!", Toast.LENGTH_SHORT).show();
}
});


How can I fix this?

Notes:
I'm using this library, and I have the libraries updated.

Update:

viewHolder.buttonDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mItemManger.removeShownLayouts(viewHolder.swipeLayout);
mResultArray.remove(position);
notifyItemRangeChanged(position, mResultArray.size());
notifyItemRemoved(position);
mItemManger.closeAllItems();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
notifyDataSetChanged();
}
}, 500);
}
});

Answer

I think you should call notifyItemRangeRemoved(position, 1); instead.