Friends I am using listview and loading contents on scroll when it reaches at the end. But I am facing error like the same url is called more than once if if scrolled fastly can anybody help me to resolve this. I have gone thro SCROLL_STATE_IDLE but don't know how to implement the same in my code. Also even when am not touching screen its running. I now want to know how to stop the code on Idle state.Attaching my code below
int start = 0;
int limit = 3;
loadingMore = false;
listView.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
// TODO Auto-generated method stub
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
// TODO Auto-generated method stub
int lastInScreen = firstVisibleItem + visibleItemCount;
if ((lastInScreen == totalItemCount) ) {
if(loadingMore == false){
start = lastInScreen - 1;
url = "http://www.dskjhf.com/web-servic/request_response.php?type=get_articles&start="
+ start + "&end=" + limit;
grabURL(url);
}
}}
});
protected void grabURL(String url) {
// TODO Auto-generated method stub
new BackgroundTask().execute(url);
loadingMore = true;
}