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?
Just remove setHasFixedSize(true)
from your initialization of RecyclerView.
mItems.add(0, item);
if(mItems.size()==1){
notifyDataSetChanged();
} else {
notifyItemInserted(position);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With