Reputation: 1
I am facing some problems with notifyItemRemoved
and notifyItemRangeChanged
.
I have a RecyclerView
which is populated by cards. Every card has its own button. I've implemented on RecyclerView's
method onBindViewHolder
an OnClickListener
for the button. When pressed, I want the card to delete itself. I have the following code:
holder.deleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mDataset.remove(holder.getAdapterPosition());
notifyItemRemoved(holder.getAdapterPosition());
notifyItemRangeChanged(holder.getAdapterPosition(), mDataset.size());
}
});
There is a strange behavior with deleting. The card I want to delete disappears for a short time then fastly reappears and if I try to press the delete button again, it gives an ArrayIndexOutOfBoundsException
error.
Did anyone experience anything like this? Any help is greatly appreciated!
Upvotes: 0
Views: 431
Reputation: 749
Remove this
notifyItemRangeChanged(holder.getAdapterPosition(), mDataset.size());
Upvotes: 1