title: Pull to refresh recyclerview android
body: <p>Hi I've a tabbed activity, and in the first tab I fetch data from server and show it in a recyclerview within card views. For fetching the data from server I use the volley library. I want to implement the Pull to refresh to load the data (so whenever I pull it has to do the request to the network). And I want also to disable the network request whenever I switch between tabs (because when I change tab focus in my app it starts to fetching data) I want to do the network request only 1 time (when user log in first time) and then others requests maneged only by pull to refresh. </p>
  
  <p>Here's my fragment where I've recyclerview and show the data:</p>
  
  <pre><code>public class Tab1History extends Fragment
  {
  
  private RecyclerView recyclerView;
  private CespiteAdapter adapter;
  UserSessionManager session;
  
  private static final String URL_DATA = "http://mydata.php";
  
  private List&lt;CespiteOgg&gt; cespiteOggList;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState)
  {
  
      View rootView = inflater.inflate(R.layout.tab1history, container, false);
  
      recyclerView = (RecyclerView) rootView.findViewById(R.id.my_recycler_view);
      recyclerView.setHasFixedSize(true);//every item of the RecyclerView has a fix size
      recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
  
      cespiteOggList = new ArrayList&lt;&gt;();
  
      loadRecyclerViewData();
  
              return rootView;
  }
  
  private void loadRecyclerViewData()
  {
      // Session class instance
      session = new UserSessionManager(getActivity());
      //get user data from session
      HashMap&lt;String, String&gt; user = session.getUserDetails();
      //get name
      String name = user.get(UserSessionManager.KEY_NAME);
      // get username
      final String usernameUtente = user.get(UserSessionManager.KEY_USERNAME);
  
      final ProgressDialog progressDialog = new ProgressDialog(getActivity());
      progressDialog.setMessage("Carimento dati...");
      progressDialog.show();
  
      StringRequest stringRequest = new StringRequest(Request.Method.POST,
              URL_DATA,
              new Response.Listener&lt;String&gt;() {
                  @Override
                  public void onResponse(String s) {
                      progressDialog.dismiss();
                      try {
                          JSONObject jsonObject = new JSONObject(s);
                          JSONArray array = jsonObject.getJSONArray("dates");
  
                          for(int i=0; i&lt;array.length(); i++)
                          {
                              JSONObject o = array.getJSONObject(i);
                              CespiteOgg item = new CespiteOgg(
                                      o.getString("CodNumInventario"),
                                      o.getString("Nome"),
                                      o.getString("DtCatalogazione"),
                                      o.getString("CodIdA"),
                                      o.getString("username")
                              );
                              cespiteOggList.add(item);
                          }
  
                          adapter = new CespiteAdapter(cespiteOggList, getActivity());
                          recyclerView.setAdapter(adapter);
  
                      } catch (JSONException e) {
                          e.printStackTrace();
                      }
  
                  }
              },
              new Response.ErrorListener() {
                  @Override
                  public void onErrorResponse(VolleyError error) {
                      progressDialog.dismiss();
                  }
              })
              {
                  @Override
                  protected Map&lt;String, String&gt; getParams() throws AuthFailureError {
                      Map&lt;String, String&gt; params = new HashMap&lt;String, String&gt;();
                      params.put("Username", usernameUtente);
                      return params;
                  }
              };
  
      RegisterRequest.getmInstance(getActivity()).addToRequestque(stringRequest);
  
  }
  }
  </code></pre>
  
  <p><strong>And it's the adapter:</strong></p>
  
  <pre><code>public class CespiteAdapter extends RecyclerView.Adapter&lt;CespiteAdapter.ViewHolder&gt;
  {
  
  
  private List&lt;CespiteOgg&gt; cespiteOggList;
  private Context context;
  
  public CespiteAdapter(List&lt;CespiteOgg&gt; cespiteOggList, Context context) {
  
      this.cespiteOggList = cespiteOggList;
      this.context = context;
  }
  
  public class ViewHolder extends RecyclerView.ViewHolder
  {
  
      public CardView cv;
      public TextView txtNumInventario;
      public TextView txtNomeCespite;
      public TextView txtDtCatalogazione;
      public TextView txtAula;
      public TextView txtNomeUser;
  
  
      ViewHolder(View itemView)
      {
  
          super (itemView);
          //cv = (CardView) itemView.findViewById(R.id.cardView);
          txtNumInventario = (TextView) itemView.findViewById(R.id.txtNumeroInventario);
          txtNomeCespite = (TextView) itemView.findViewById(R.id.txtNomeCespite);
          txtDtCatalogazione = (TextView) itemView.findViewById(R.id.txtDataCatalogazione);
          txtAula = (TextView) itemView.findViewById(R.id.txtAula);
          txtNomeUser= (TextView) itemView.findViewById(R.id.txtNomeUser);
  
  
      }
  }
  
  
  
  @Override
  public CespiteAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
  {
  
      LayoutInflater inflater = LayoutInflater.from(parent.getContext());
  
      View cespiteView = inflater.inflate(R.layout.cespite_card_view, parent, false);
  
      return new ViewHolder(cespiteView);
  }
  
  @Override
  public void onBindViewHolder(ViewHolder holder, int position)
  {
  
      CespiteOgg cespiteOgg = cespiteOggList.get(position);
  
      holder.txtNumInventario.setText(cespiteOgg.getNumInventario());
      holder.txtNomeCespite.setText(cespiteOgg.getNomeCespite());
      holder.txtDtCatalogazione.setText(cespiteOgg.getDtCatalogazione());
      holder.txtAula.setText(cespiteOgg.getAula());
      holder.txtNomeUser.setText(cespiteOgg.getNomeUser());
  
  }
  
  @Override
  public int getItemCount()
  {
  
      return cespiteOggList.size();
  }
  
  }
  </code></pre>