title: How to load records dynamically in listview with help of Bottom progressbar
body: <p>Hi i am very new for android and in my case i have 200 above records i have to show in my list-view that's why i request to server offset value </p>
  
  <p>so that based on offset value server sending records for this i wrote below code but duplicate records also adding in my ArrayList  how can we resolve please help</p>
  
  <p>my code is below very clearly and i am sending server link also please help me</p>
  
  <h2>code:-</h2>
  
  <pre><code>public class MainActivity extends Activity {
  
      private ListView lv;
      private ProgressDialog pDialog;
      private ListViewAdapter adapter;
      private ArrayList&lt;String&gt; arrayList;
      private int scrollState;
      private int offset = 0;
      private boolean flag = false;
      private boolean loadingMore = false;
      ProgressBar pb;
      private int scrollpos;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          lv = (ListView) findViewById(R.id.list);
  
          if (savedInstanceState == null) {
              arrayList = new ArrayList&lt;&gt;();
          } else {
              arrayList = (ArrayList&lt;String&gt;)savedInstanceState.getSerializable("list");
          }
  
          //Adding footer for ListView:-
          pb = new ProgressBar(this);
          lv.addFooterView(pb);
  
          //Setting Adapter:-
          adapter = new ListViewAdapter(this, arrayList);
          lv.setAdapter(adapter);
  
          if (!flag) {
              new loadMoreListView().execute();
              flag = true;
          }
  
          lv.setOnScrollListener(new AbsListView.OnScrollListener() {
              @Override
              public void onScrollStateChanged(AbsListView view, int scrollState) {
                  MainActivity.this.scrollState = scrollState;
              }
  
              @Override
              public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
                                   int totalItemCount) {
  
                  scrollpos = totalItemCount;
                  int lastPos = firstVisibleItem + visibleItemCount;
  
                  if (lastPos == totalItemCount &amp;&amp; !loadingMore) {
  
                      if (totalItemCount &lt; 250) {
                          new loadMoreListView().execute();
                      } else {
                          lv.removeFooterView(pb);
                      }
                  }
              }
          });
      }
  
      @Override
      protected void onSaveInstanceState(Bundle outState) {
          super.onSaveInstanceState(outState);
          outState.putSerializable("list", arrayList);
      }
  
      @Override
      protected void onRestoreInstanceState(Bundle savedInstanceState) {
          super.onRestoreInstanceState(savedInstanceState);
          arrayList = (ArrayList&lt;String&gt;) savedInstanceState.getSerializable("list");
      }
  
      private class loadMoreListView extends AsyncTask&lt;Void, Void, String&gt; {
  
          protected String doInBackground(Void... unused) {
              loadingMore = true;
              String result = null;
              String url = "http://api.androidhive.info/json/imdb_top_250.php?offset=" + offset;
              try {
                  URL mUrl = new URL(url);
                  HttpURLConnection urlConnection = (HttpURLConnection) mUrl.openConnection();
                  urlConnection.connect();
                  InputStream inputStream = urlConnection.getInputStream();
                  BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
                  StringBuffer buffer = new StringBuffer();
                  String str = "";
                  while ((str = br.readLine()) != null) {
                      buffer.append(str);
                  }
                  result = buffer.toString();
              } catch (Exception e) {
                  e.printStackTrace();
              }
              return result;
          }
  
          protected void onPostExecute(String result) {
  
              System.out.println("Result is"+result);
  
              if (result != null) {
                  try {
  
                      JSONArray array = new JSONArray(result);
                      for (int i = 0; i &lt; array.length(); i++) {
                          arrayList.add(array.getJSONObject(i).getString("title"));
                      }
  
                      System.out.println("arry list count is====&gt;"+arrayList.size());
                      adapter.notifyDataSetChanged();
                      offset++;
                     // offset = offset + 10;
                      loadingMore = false;
  
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              } else {
                  lv.removeFooterView(pb);
              }
          }
      }
  }
  </code></pre>