notifyItemInserted() not working as I was expecting

Viewed 6941

What I need to do is inserting item to the top of RecyclerView. I have adapter which persists List of my items and when I want to add to the top of RecyclerView I'm simply using this code:

mItems.add(0, item);
notifyItemInserted(0)

Unfortunately it's just reloading last item of RecyclerView. Of course when I change notifyItemInserted to notifyDataSetChanged() everything works fine. Why is notifyItemInserted not appropriate?

2 Answers

Just remove setHasFixedSize(true) from your initialization of RecyclerView.

mItems.add(0, item);

if(mItems.size()==1){

   notifyDataSetChanged();
} else {

notifyItemInserted(position);

}
Related