title: Updating dataset in recyclerview while scrolling sends the scroll to the top
body: <p>Needless to say, I came across a lot of proposed solutions for this particular problem. I removed scrollListener and implemented it inside my fragment, I used notifyItemRangeInserted instead of notifyDataSetChanged. The thing is, none of those solutions did work for me...I'm displaying a set of youtube videos in my app. My dataset is indeed updated; thing is when I scroll downwards, at some point the scroll position moves to the top i.e the very first item of my dataset  Here's a snippet of my activity :</p>
  
  <pre><code>private void setUpRecyclerView()
  {
      mRecyclerView.setHasFixedSize(true);
      linearLayoutManager = new LinearLayoutManager(getActivity());
      linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
      mRecyclerView.setLayoutManager(linearLayoutManager);
      mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
          @Override
          public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
              super.onScrolled(recyclerView, dx, dy);
              totalItemCount = linearLayoutManager.getItemCount();
              lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition();
              if (!loading &amp;&amp; totalItemCount &lt;= (lastVisibleItem + visibleThreshold))
              {
                  loadMorePosts();
                  loading = true;
              }
          }
      });
  
      initAdapter();
  }
  
  private void initAdapter()
  {
      adapter = new MyAdapter(mDataSet, getActivity());
      mRecyclerView.setAdapter(adapter);
      skeletonScreen = Skeleton.bind(mRecyclerView)
              .adapter(adapter)
              .shimmer(true)
              .angle(30)
              .duration(1200)
              .count(10)
              .load(R.layout.youtube_item)
              .show();
  }
  
  private void loadVideos(final OnLoadPlayListCallback videosCallback, String pageToken)
  {
      Call&lt;FullChannelPlayListData&gt; mcallPlayList = mYouTubeService.getPlayList(
              Tags.VALUE_SNIPPET,
              20,
              mPlayListId,
              getActivity().getResources().getString(R.string.youtube_data_api_key),
              pageToken
              );
  
      mcallPlayList.enqueue(new Callback&lt;FullChannelPlayListData&gt;() {
          @Override
          public void onResponse(Call&lt;FullChannelPlayListData&gt; call, Response&lt;FullChannelPlayListData&gt; response) {
              if (response.code() == 200)
              {
                  Log.d("FullPlayListSuccessful", response.message());
                  videosCallback.onSuccessfulRequest(response.body());
              }
              else Log.d("FullPlayListUnsuccess", response.message());
  
          }
  
          @Override
          public void onFailure(Call&lt;FullChannelPlayListData&gt; call, Throwable t) {
              videosCallback.onFailureRequest(t);
          }
      });
  }
  
   @Override
  public void onSuccessfulRequest(FullChannelPlayListData fullChannelPlayListData)
  {
      Log.d(TAG, "onSuccessfulRequest Item size = "+ fullChannelPlayListData.getItems().size());
      if (StringUtils.isNotEmpty(mNextPageToken))
          removeFooter();
  
      for (FullPlayListItems mItem: fullChannelPlayListData.getItems())
      {
          FullPlayListItems randomItem = getVideoFromDataSet(mItem.getSnippet().getResourceId().getVideoId(), mDataSet);
          if (randomItem == null) {
              mDataSet.add(mItem);
          }
      }
  
      adapter.notifyItemRangeInserted(adapter.getItemCount(), mDataSet.size());
  
      mRecyclerView.postDelayed(new Runnable() {
          @Override
          public void run() {
              skeletonScreen.hide();
          }
      }, 2000);
  
  
      mNextPageToken = fullChannelPlayListData.getNextPageToken();
      setLoaded();
  
  }
  
  public void setLoaded() {
      loading = false;
  }
  </code></pre>
  
  <p>I could use really use some help...</p>
  
  <p><strong>UPDATE</strong> MyAdapter class</p>
  
  <pre><code> public class MyAdapter extends RecyclerView.Adapter&lt;RecyclerView.ViewHolder&gt;
  {
  
      private List&lt;FullPlayListItems&gt; mDataSet;
      private Context mActivity;
      private static final int YOUTUBE_ITEM_VIEW_TYPE = 0;
      private static final int PROGRESS_BAR_ITEM_VIEW_TYPE = 1;
  
      public MyAdapter(List&lt;FullPlayListItems&gt; mDataSet, Context mActivity) {
          this.mDataSet = mDataSet;
          this.mActivity = mActivity;
      }
  
  
      public class ProgressViewHolder extends RecyclerView.ViewHolder
      {
          @BindView(R.id.pBarLoadMorePosts)
          ProgressBar pBarLoadMore;
  
          public ProgressViewHolder(View itemView) {
              super(itemView);
              ButterKnife.bind(this, itemView);
          }
      }
  
  
      @Override
      public int getItemViewType(int position) {
          return mDataSet.get(position) != null ? YOUTUBE_ITEM_VIEW_TYPE : PROGRESS_BAR_ITEM_VIEW_TYPE;
      }
  
      @Override
      public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
      {
          RecyclerView.ViewHolder viewHolder;
          if (viewType == PROGRESS_BAR_ITEM_VIEW_TYPE)
          {
              View pBarLayoutView = LayoutInflater.from(parent.getContext())
                      .inflate(R.layout.footer_loader, parent, false);
              viewHolder = new ProgressViewHolder(pBarLayoutView);
          }
          else
          {
              View postItemLayoutView = LayoutInflater.from(parent.getContext())
                      .inflate(R.layout.youtube_item, parent, false);
              viewHolder = new YoutubeItemViewHolder(postItemLayoutView);
          }
          return viewHolder;
      }
  
      @Override
      public void onBindViewHolder(RecyclerView.ViewHolder holder, int position)
      {
          int viewType = getItemViewType(position);
          FullPlayListItems mVideoItem = mDataSet.get(position);
  
          switch (viewType)
          {
              case PROGRESS_BAR_ITEM_VIEW_TYPE:
                  ProgressViewHolder progressViewHolder = (ProgressViewHolder) holder;
                  progressViewHolder.pBarLoadMore.getIndeterminateDrawable().setColorFilter(CoreApplication.getRes().getColor(R.color.colorPrimary), PorterDuff.Mode.SRC_IN);
                  break;
              case YOUTUBE_ITEM_VIEW_TYPE:
              default:
                  YoutubeItemViewHolder youtubeItemViewHolder = (YoutubeItemViewHolder) holder;
                  youtubeItemViewHolder.mVideoTitle.setText(mVideoItem.getSnippet().getTitle());
                  youtubeItemViewHolder.sdvYoutubeThumbnail.setImageURI(Uri.parse(mVideoItem.getSnippet().getThumbnails().getHigh().getUrl()));
  
          }
      }
  
  
      @Override
      public int getItemCount() {
          return mDataSet != null ? mDataSet.size() : 0;
      }
  
      public class YoutubeItemViewHolder extends RecyclerView.ViewHolder
      {
          TextView mVideoTitle;
          SimpleDraweeView sdvYoutubeThumbnail;
  
          public YoutubeItemViewHolder(View itemView)
          {
              super(itemView);
              mVideoTitle = (TextView)itemView.findViewById(R.id.tv_video_title);
              sdvYoutubeThumbnail = (SimpleDraweeView)itemView.findViewById(R.id.sdv_thumbnail);
          }
      }
  }
  </code></pre>
  
  <p>And here is my onViewCreated:</p>
  
  <pre><code>@Override
  public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
      super.onViewCreated(view, savedInstanceState);
      mPlayListId = getArguments().getString(Tags.YT_CHANNEL_PLAYLIST_ID);
      setUpRecyclerView();
      // Like I said initially mNextPageToken is empty
      loadVideos(this, mNextPageToken);
  }
  </code></pre>