title: RecyclerView not scrolling to upword shows previous Items
body: <p>I am having a problem with parse data using offset in recyclerview. At the moment I am able to show the first 30 items having offset 0. Then I am detecting when scroll reach to the end of list item, then again service call but this time I could not be able to scroll up for my previous items, every time a set of 30 new items comes, but no previous items. Can I resolved this with out using any third part lib? </p>
  
  <pre><code>private boolean loading = true;
  int pastVisiblesItems, visibleItemCount, totalItemCount,firstVisibleInListview;
  
  private RecyclerView unitListView;
  LinearLayoutManager mLayoutManager;
  private NumberOfUnitsAdapter unitsAdapter;
  private List&lt;UnitsModel&gt; unitsModelList;
  private SessionManager sessionManager;
  
  public static final String KEY_TOKEN = "token";
  private String token;
  
   int offSet = 0;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_number_of_units);
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
      sessionManager = new SessionManager(getApplicationContext());
      unitListView = (RecyclerView) findViewById(R.id.unitlist);
      unitsModelList = new ArrayList&lt;&gt;();
  
      unitListView.setHasFixedSize(true);
      mLayoutManager = new LinearLayoutManager(this);
      unitListView.setLayoutManager( mLayoutManager );
      unitListView.setItemAnimator(new DefaultItemAnimator());
      unitsAdapter = new NumberOfUnitsAdapter(getApplicationContext(),unitsModelList,unitListView);
      unitListView.setAdapter(unitsAdapter);
  
      unitListView.addOnScrollListener(new RecyclerView.OnScrollListener()
      {
          @Override
          public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
              super.onScrolled(recyclerView, dx, dy);
  
              unitListView.getLayoutManager().canScrollVertically();
              if(dy&gt; 0)
              {
                   visibleItemCount = mLayoutManager.getChildCount();
                   totalItemCount = mLayoutManager.getItemCount();
                   pastVisiblesItems = mLayoutManager.findFirstVisibleItemPosition();
  
                  if (loading)
                  {
                      if ( (visibleItemCount + pastVisiblesItems) &gt;= totalItemCount)
                      {
                          loading = false;
                          Log.v("...", "Last Item Wow !");
                          Toast.makeText(getApplicationContext(), "Last Station Agaya hai Bahi",
                                  Toast.LENGTH_LONG).show();
                          //Do pagination.. i.e. fetch new data
                          callUnitAPI();
                          loading = true;
                      }
                  }
              }
          }
      });
  
      callUnitAPI();
  
  }
  
  private void callUnitAPI() {
  
      Map&lt;String, String&gt; jsonParams = new HashMap&lt;&gt;();
      HashMap&lt;String, String&gt; user = sessionManager.getUserDetails();
      token = user.get(SessionManager.TOKEN);
      jsonParams.put(KEY_TOKEN, token);
     String url = createGetWithParams(Constant.BASE_URL+UNITS_API+offSet,jsonParams);
      JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
              new Response.Listener&lt;JSONObject&gt;() {
                  private String unitName ,unitNumber;
                  private int unitId,unitBedroom,unitBathroom,unitBuildArea,unitPlotArea;
                  private float unitPrice;
                  @Override
                  public void onResponse(JSONObject response) {
                      unitsModelList.clear();
                      if (response.length() &gt; 0) {
  
                          try {
  
                              JSONArray ownersData = response.getJSONArray("units");
                              for (int i = 0; i &lt; ownersData.length(); i++) {
                                  JSONObject jsonObj = ownersData.getJSONObject(i);
                                  unitName = jsonObj.getString("Jhon");
                                  unitNumber = jsonObj.getString("unitq");
                                  unitId = Integer.parseInt(jsonObj.getString("iden"));
                                  unitPlotArea = Integer.parseInt(jsonObj.getString("plan"));
                                  unitBuildArea = Integer.parseInt(jsonObj.getString("build"));
                                  unitBedroom = Integer.parseInt(jsonObj.getString("bed"));
                                  unitBathroom = Integer.parseInt(jsonObj.getString("bath"));
                                  unitPrice = BigDecimal.valueOf(jsonObj.getDouble("pro")).floatValue();
  
                                  UnitsModel numUnitModel = new UnitsModel();
                                  numUnitModel.setUnitName(unitName);
                                  numUnitModel.setUnitNumber(unitNumber);
                                  numUnitModel.setUnitId(unitId);
                                  numUnitModel.setUnitPlotArea(unitArea);
                                  numUnitModel.setUnitBuildArea(uniBArea);
                                  numUnitModel.setUnitBedroom(unitBedroom);
                                  numUnitModel.setUnitBathroom(unitBathroom);
                                  numUnitModel.setUnitPrice(unitPrice);
                                  unitsModelList.add(numUnitModel);
                                  if(unitId &gt;= offSet)
                                      offSet = unitId;
  
                              }
  
  
                          } catch (Exception e) {
                              e.printStackTrace();
                              Toast.makeText(getApplicationContext(),
                                      "Error: " + e.getMessage(),
                                      Toast.LENGTH_LONG).show();
                          }
  
                          unitsAdapter.addUnitsModels(unitsModelList);
                          unitsAdapter.notifyDataSetChanged();
                      }
                  }
  
              },
  
              new Response.ErrorListener() {
                  @Override
                  public void onErrorResponse(VolleyError response) {
                      NetworkResponse networkResponse = response.networkResponse;
                      if (networkResponse != null &amp;&amp; networkResponse.statusCode == 401) {
                          Toast.makeText(getApplicationContext(), "Token Expire", Toast.LENGTH_LONG).show();
                      }
  
                  }
  
              });
  
  
      AppController.getInstance().addToRequestQueue(request);
  
  }
  </code></pre>
  
  <p>Here is the Adapter <strong>Updated</strong> </p>
  
  <pre><code>  public class NumberOfUnitsAdapter extends RecyclerView.Adapter {
  
      private final int VIEW_ITEM = 1;
      private final int VIEW_PROG = 0;
      private Activity activity;
  
      private List&lt;UnitsModel&gt; unitsModelList;
  
      private OnLoadMoreListener onLoadMoreListener;
      Context mContext;
      public NumberOfUnitsAdapter( Context mContext, List&lt;UnitsModel&gt; unitsModelList,RecyclerView recyclerView) {
          this.mContext = mContext;
          this.unitsModelList = unitsModelList;
  
      }
      @Override
      public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent,
                                                        int viewType) {
          RecyclerView.ViewHolder vh;
          if (viewType == VIEW_ITEM) {
              View v = LayoutInflater.from(parent.getContext()).inflate(
                      R.layout.numberofunits_items, parent, false);
  
              vh = new NumberOfUnitsHolder(v);
          } else {
              View v = LayoutInflater.from(parent.getContext()).inflate(
                      R.layout.progress_item, parent, false);
  
              vh = new ProgressViewHolder(v);
          }
          return vh;
      }
  
  
      @Override
      public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
          UnitsModel unitsModel= unitsModelList.get(position);
          if (holder instanceof NumberOfUnitsHolder) {
              NumberOfUnitsHolder vholder = (NumberOfUnitsHolder) holder;
              vholder.unitName.setText(unitsModel.getUnitNumber());
              vholder.manageBtn.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
  
                      Bundle bundle = new Bundle();
                      bundle.putString("UNIT_NAME", unitsModelList.get(position).getUnitName());
                      bundle.putString("UNIT_NUMB", unitsModelList.get(position).getUnitNumber());
                      bundle.putFloat("UNIT_PRICE", unitsModelList.get(position).getUnitPrice());
                      bundle.putInt("UNIT_PLOT", unitsModelList.get(position).getUnitPlotArea());
                      bundle.putInt("UNIT_BUILD", unitsModelList.get(position).getUnitBuildArea());
                      bundle.putInt("UNIT_BATH", unitsModelList.get(position).getUnitBathroom());
                      bundle.putInt("UNIT_BED", unitsModelList.get(position).getUnitBedroom());
                      bundle.putInt("UNIT_ID", unitsModelList.get(position).getUnitId());
  
                      Intent itemClick = new Intent(mContext, NumOfUnitDetail.class);
                      itemClick.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                      itemClick.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                      itemClick.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                      itemClick.putExtras(bundle);
                      mContext.startActivity(itemClick);
  
                  }
              });
          }
  
          else {
              ((ProgressViewHolder) holder).progressBar.setIndeterminate(true);
          }
    }
  
      @Override
      public int getItemCount() {
          return unitsModelList.size();
  
  
      }
  
      @Override
      public int getItemViewType(int position) {
          return unitsModelList.get(position) != null ? VIEW_ITEM : VIEW_PROG;
      }
  
      public void addUnitsModels(List&lt;UnitsModel&gt; unitsModelList) {
          this.unitsModelList.addAll(unitsModelList);
      }
  
      public class NumberOfUnitsHolder extends RecyclerView.ViewHolder {
          public final View mView;
          public final TextView unitName;
          public final Button historyBtn;
          public final Button manageBtn;
          public NumOwnerModel mItem;
  
          public NumberOfUnitsHolder(View view) {
              super(view);
              mView = view;
              unitName = (TextView)view.findViewById(R.id.unitNo);
              historyBtn= (Button) view.findViewById(R.id.historyBtn);
              manageBtn = (Button) view.findViewById(R.id.manageBtn);
  
          }
      }
  
  
      public static class ProgressViewHolder extends RecyclerView.ViewHolder {
          public ProgressBar progressBar;
  
          public ProgressViewHolder(View v) {
              super(v);
              progressBar = (ProgressBar) v.findViewById(R.id.progressBar1);
          }
      }
  }
  </code></pre>