Load more list with JSON array Android
You should use boolean for that.
lv.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView absListView, int i) { int threshold = 1; int count = lv.getAdapter().getCount(); if (i == SCROLL_STATE_IDLE) { if (lv.getLastVisiblePosition() >= count - threshold) { // Execute LoadMorePerformTask AsyncTask; new LoadMorePerformTask().execute(); } } } @Override public void onScroll(AbsListView absListView, int i, int i1, int i2) { } });
The problem is here in your code. You are create request every list reaches to its bottom. You need to keep a boolean isLoaded = false
and before firing the request when list reaches to its bottom check if isLoaded
is true
then fire the request and in your async task you can set the boolean true when result is received and set it to false after firing the request.
if (i == SCROLL_STATE_IDLE) { if (lv.getLastVisiblePosition() >= count- threshold) { // Execute LoadMorePerformTask AsyncTask; if(isLoaded){ new LoadMorePerformTask().execute(); isLoaded=false } }
and in aysc
protected void onPostExecute(String result) { super.onPostExecute(result); isLoaded = true; //and your rest of the code}
Hope this will help.