title: update data in custom adapter using swipeRefreshLayout
body: <p>I am trying to update the data using swipeRefreshLayout, but every time I swipe down to refresh it repeats the old ones instead of showing the new data.</p>
  
  <p>Can you please help me with that and show me where did i make the mistake and how to fix it.</p>
  
  <p>My code in fragment:</p>
  
  <pre><code>public class StoriesFragment extends Fragment {
  
      private static final String TAG = MainActivity.class.getSimpleName();
  
      private static final String url = "http://sho3a3.net/storiesfeed.json";
  
      private ProgressDialog pDialog;
      private List&lt;StoriesItem&gt; storiesListItem = new ArrayList&lt;StoriesItem&gt;();
      private ListView storiesListView;
      private CustomListAdapter adapter;
  
      private SwipeRefreshLayout swipeRefreshLayout;
  
      public StoriesFragment() {
          // Required empty public constructor
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          // Inflate the layout for this fragment
          View view = inflater.inflate(R.layout.stories_fragment, container, false);
  
          /*Swipe Refresh Layout*/
  
          swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_container);
          swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
              @Override
              public void onRefresh() {
                  adapter.notifyDataSetChanged();
                  getDataFromUrl();
              }
  
          });
          swipeRefreshLayout.setColorScheme(
                  android.R.color.holo_blue_bright,
                  android.R.color.holo_green_light,
                  android.R.color.holo_orange_light,
                  android.R.color.holo_red_light);
  
  
          swipeRefreshLayout.post(new Runnable() {
              @Override
              public void run() {
                  swipeRefreshLayout.setRefreshing(true);
  
                  getDataFromUrl();
              }
          });
  
          storiesListView = (ListView) view.findViewById(R.id.list);
          adapter = new CustomListAdapter(getActivity(), storiesListItem);
          storiesListView.setAdapter(adapter);
  
          /*Click Feed Item */
          storiesListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView&lt;?&gt; adapterView, View view, int i, long l) {
                  Toast.makeText(getActivity(), " " + i, Toast.LENGTH_SHORT).show();
  
                  Object o = storiesListView.getItemAtPosition(i);
                  StoriesItem storiesItem = (StoriesItem) o;
                  Intent intent = new Intent(getActivity(), DetailsActivity.class);
                  intent.putExtra("storiesItem", storiesItem);
                  startActivity(intent);
  
              }
          });
  
          return view;
      }
  
      private void getDataFromUrl() {
  
          // RequestQueue requestQueue = Volley.newRequestQueue(getActivity());
          // Creating volley request obj
          JsonArrayRequest movieReq = new JsonArrayRequest(url,
                  new Response.Listener&lt;JSONArray&gt;() {
                      @Override
                      public void onResponse(JSONArray response) {
                          Log.d(TAG, response.toString());
                          //hidePDialog();
  
                          String title;
                          String date;
                          String profession;
                          // Parsing json
                          for (int i = 0; i &lt; response.length(); i++) {
                              try {
  
                                  JSONObject obj = response.getJSONObject(i);
                                  StoriesItem storiesItem = new StoriesItem();
  
                                  //Title
                                  title = obj.getString("title");
                                  byte[] bytesTitle = title.getBytes("ISO-8859-1");
                                  String stringTitle = new String(bytesTitle, "UTF-8");
                                  storiesItem.setTitle(stringTitle);
  
                                  //Date
                                  date = obj.getString("date");
                                  byte[] bytesDate = date.getBytes("ISO-8859-1");
                                  String stringDate = new String(bytesDate, "UTF-8");
                                  storiesItem.setDate(stringDate);
  
  
                                  //Profession
                                  profession = obj.getString("profession");
                                  byte[] bytesProfession = profession.getBytes("ISO-8859-1");
                                  String stringProfession = new String(bytesProfession, "UTF-8");
                                  storiesItem.setProfession(stringProfession);
  
  
                                  storiesItem.setThumbnailUrl(obj.getString("image"));
                                  storiesItem.setContent(obj.getString("content"));
  
  
                                  // adding movie to movies array
                                  storiesListItem.add(storiesItem);
  
  
                              } catch (JSONException e) {
                                  e.printStackTrace();
                              } catch (UnsupportedEncodingException e) {
                                  e.printStackTrace();
                              }
  
                          }
  
                          // swipeRefreshLayout.setRefreshing(false);
                          onItemsLoadComplete();
                          // notifying list adapter about data changes
                          // so that it renders the list view with updated data
  
  
                          adapter.notifyDataSetChanged();
                      }
                  }, new Response.ErrorListener() {
              @Override
              public void onErrorResponse(VolleyError error) {
                  Toast.makeText(getActivity(), "Error Connection", Toast.LENGTH_SHORT).show();
                  VolleyLog.d(TAG, "Error: " + error.getMessage());
                  swipeRefreshLayout.setRefreshing(false);
                  //hidePDialog();
  
              }
          });
  
          //requestQueue.add(movieReq);
          // Adding request to request queue
          AppController.getInstance().addToRequestQueue(movieReq);
      }
  
      void onItemsLoadComplete() {
          // Update the adapter and notify data set changed
          // ...
          adapter.notifyDataSetChanged();
          // Stop refresh animation
          swipeRefreshLayout.setRefreshing(false);
      }
  
      public void onUpdate() {
          adapter = new CustomListAdapter(getActivity(), storiesListItem);
          storiesListView.setAdapter(adapter);
          if (swipeRefreshLayout.isRefreshing()) {
              swipeRefreshLayout.setRefreshing(false);
          }
      }
  }
  </code></pre>