How to remain at a scroll position in RecyclerView after adding items at its first index and call notifydatasetchange

I am using a RecyclerView, I add items before the first item, the scroll position moves up to the newly first item added. How can I maintain my scroll position after adding new items at its first index and call notifydatasetchange() ?

this is what i do in my adapter

  • Use two pendingIntent on one view in Appwidget
  • Android - Set text to TextView
  • Prevent onPause from trashing OpenGL Context
  • Dynamically adding and removing table rows - Android
  • Android & iOS: How to develop for both?
  • ListPreference dependency
  •     mCurrentFragment.items.addAll(0, createLineItems(dataArrayList));
    
        notifyDataSetChanged();
    

    Any suggestions ?

    Related posts:

    Can I re-sign an .apk with a different certificate than what it came with?
    re-setting a TextView height programmatically
    Facebook overlay animation
    ArrayIndexOutOfBoundsException when using ListAdapter
    eclipse can't locate my sdk folder
    Linear Algebra Library For Android
  • Android ListView in fragment example
  • Android: Fragment's new getContext() method is which context?
  • Invalid project description when importing project into Eclipse
  • Download and Save Images Using Picasso
  • How to update column with ORMLite
  • Android L - Floating Action Button (FAB)
  • One Solution collect form web for “How to remain at a scroll position in RecyclerView after adding items at its first index and call notifydatasetchange”

    There are two options:

    1. Use the more sophisticated versions of notify

      List newData = createLineItems(dataArrayList);
      mCurrentFragment.items.addAll(0, newData);
      notifyItemRangeInserted(0, newData.size());
      
    2. Use stable IDs. On your adapter override public long getItemId (int position) to make it return MEANINGFUL values and call setHasStableIds(true); on it.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.