recyclerview-animators
recyclerview-animators copied to clipboard
notifyItemRemoved just work for the First removed
im my Adapter inside the
public void onBindViewHolder(ViewHolder holder, final int position)
i have this:
holder.new_text_remove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
realmDB = new RealmDB(activity);
realmDB.updateOrCreateLei(mDataset.get(position));
Snackbar.make(activity.getCurrentFocus(), mDataset.get(position) + " Removed", Snackbar.LENGTH_SHORT).show();
mDataset.remove(position);
notifyItemRemoved(position);
}
});
obs: moving remove and notify to a function not resolve for the first time i delete it works normally, but in the second it delete the next not the clicked one
example:
Before deleting:
- A
- B
- C
- D
- E
deleting letter A:
- B
- C
- D
- E
perfect, but when i click to delete letter B after deleting letter A, it delete letter C, maybe notifyData is not working?
i check somethings and i can confirm that the notifyItemRemoved is not "reordering" the things like the remove, i mean, when you mDataSet.remove() it already update the list, but the notifyItemRemoved doesnt know that, so when you click to remove again, i will try to remove position X, but the .remove() already changed that position o0
I think this question should not be asked for this library, since the removal of an item is part of RecyclerView.Adapter
. For the resolution of your problem you should better have a look at my adapter, see my repository.
I have come acrossed this problem, so how do you deal with it?
@huangjim, it is strange indeed, probably it's because onBindViewHolder is called everytime you call notify and that final might lead to some weird behaviour. Try to implement the delete from the Activity, also you should better to not implement the click listener in that method since it is called every time a new row is bound. So, again have a look at my adapter.