title: How to append new Listview data to infinite scrolling ListView
body: <p>I am trying to implement infinite scrolling in my app ListView but the results i am getting is that the ListView is getting populated with new data instead of getting appended.</p>
  
  <p>I am getting noclue what's ever ... please help me ... the snippets are </p>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>public class MainActivity extends FragmentActivity{
   @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_near_me);
   }
    CityListFragment cityFragment = new CityListFragment();
              getSupportFragmentManager().beginTransaction()
                      .add(R.id.fragment_container, cityFragment).commit();
  }
  </code></pre>
  
  <p><strong>CityListFragment.java</strong></p>
  
  <pre><code>public class CityListFragment extends Fragment {
  
  private List&lt;City&gt; city;
  private ListView listView;
  CityListAdapter adapter;
  ProgressDialog mProgressDialog;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      new MyTask().execute();
  }
  
   public class MyTask extends AsyncTask&lt;String, Void, List&lt;City&gt;&gt; {
  
      @Override
      protected List&lt;City&gt; doInBackground(String... urls) {
          try {
              city = serviceProvider.getService().getCities();
          } catch (IOException e) {
              e.printStackTrace();
          }
          return city;
      }
  
      @Override
      protected void onPostExecute(List&lt;City&gt; organization) {
          adapter = new CityListAdapter(getActivity(), city);
          listView.setAdapter(adapter);
          // Create an OnScrollListener
          listView.setOnScrollListener(new AbsListView.OnScrollListener() {
  
              @Override
              public void onScrollStateChanged(AbsListView view,
                                               int scrollState) { // TODO Auto-generated method stub
                  int threshold = 1;
                  int count = listView.getCount();
  
                  if (scrollState == SCROLL_STATE_IDLE) {
                      if (listView.getLastVisiblePosition() &gt;= count
                              - threshold) {
                          // Execute LoadMoreDataTask AsyncTask
                          new LoadMoreDataTask().execute();
                      }
                  }
              }
          });
      }
  }
  
  public class LoadMoreDataTask extends AsyncTask&lt;String, Void, List&lt;City&gt;&gt; {
      @Override
      protected List&lt;City&gt; doInBackground(String... urls) {
          try {
              // web service request
              city = serviceProvider.getService().getNextCities();
          } catch (IOException e) {
              e.printStackTrace();
          }
          return city;
      }
  
      @Override
      protected void onPostExecute(List&lt;City&gt; organization) {
          int position = listView.getLastVisiblePosition();
          adapter = new CityListAdapter(getActivity(), city);
          listView.setAdapter(adapter);
          adapter.notifyDataSetChanged();
          listView.setSelectionFromTop(position, 0);
          mProgressDialog.dismiss();
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Instead of appending the new record into the List it is deleting the old record in the ListView 
  I followed this particular link for the Endless listview implementation</p>
  
  <p><a href="http://www.androidbegin.com/tutorial/android-parse-com-listview-load-more-using-onscrolllistener-tutorial/" rel="nofollow">http://www.androidbegin.com/tutorial/android-parse-com-listview-load-more-using-onscrolllistener-tutorial/</a></p>