24

I use notifyItemRemoved() method I want to change other remaining item , but the method doesn't trigger onBindView() method.

How can I do that, except using the notifyDataSetChanged(). I want to have the animation that comes with notifyItemRemoved() method

Vipul Asri
  • 8,903
  • 3
  • 46
  • 71
wonTonx
  • 242
  • 1
  • 2
  • 6

1 Answers1

49

If you are trying to remove an item from RecyclerView Adapter and want to show animation all over your list in RecyclerView.

after using notifyItemRemoved(position) use notifyItemRangeChanged(position, getItemCount());

notifyItemRemoved(position); - notifies the RecyclerView Adapter that data in adapter has been removed at a particular position.

notifyItemRangeChanged(position, getItemCount()); - notifies the RecyclerView Adapter that positions of element in adapter has been changed from position(removed element index to end of list), please update it.

Refer this RecyclerView insert /remove animation answer.

Community
  • 1
  • 1
Vipul Asri
  • 8,903
  • 3
  • 46
  • 71
  • Encountered a problem similar but this ```fix``` should not do anything. Look to the RecyclerVIew code: public final void notifyItemRemoved(int position) { mObservable.notifyItemRangeRemoved(position, 1); } – Vincent D. May 24 '16 at 21:19
  • 1
    @VincentD. This fix does do something. Note that the fix uses `notifyItemRangeChanged` instead of `notifyItemRangeRemoved`. – Weekend Nov 04 '16 at 06:27
  • You may also write: `notifyItemRangeChanged(position, getItemCount() - position);`. – CoolMind Aug 04 '17 at 12:37