recyclerview-animators icon indicating copy to clipboard operation
recyclerview-animators copied to clipboard

notifyItemRemoved just work for the First removed

Open defaultbr opened this issue 9 years ago • 4 comments

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:

  1. A
  2. B
  3. C
  4. D
  5. E

deleting letter A:

  1. B
  2. C
  3. D
  4. E

perfect, but when i click to delete letter B after deleting letter A, it delete letter C, maybe notifyData is not working?

defaultbr avatar Nov 13 '15 15:11 defaultbr

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

defaultbr avatar Nov 13 '15 16:11 defaultbr

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.

davideas avatar Nov 26 '15 00:11 davideas

I have come acrossed this problem, so how do you deal with it?

huangjim avatar Dec 02 '15 01:12 huangjim

@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.

davideas avatar Dec 02 '15 10:12 davideas