I want to load data when ScrollView reach at the threshold. First, I want to show last 20 rows from database and show in ListView then after using SwipeRefreshLayout load another 20 rows get from database and show in ListView and so on...
Thank you
I want to load data when ScrollView reach at the threshold. First, I want to show last 20 rows from database and show in ListView then after using SwipeRefreshLayout load another 20 rows get from database and show in ListView and so on...
Thank you
What you are searching for is called EndlessScrollListener. You will have to extend the class EndlessScrollListener
and implement the onLoadMore
method.
public class MyEndlessScrollListener extends EndlessScrollListener {
@Override
public void onLoadMore(int page, int totalItemsCount) {
loadData(page);
}
}
And set the listener on the listView :
listView.setOnScrollListener(new EndlessScrollListener());
You can use the other constructors of the EndlessScrollListener
if you want.
This is what I used to load more data at the end of the listview
listview.setOnScrollListener(new OnScrollListener(){
@Override
public void onScroll(AbsListView view,
int firstVisibleItem, int visibleItemCount,
int totalItemCount) {
//Algorithm to check if the last item is visible or not
final int lastItem = firstVisibleItem + visibleItemCount;
if(lastItem == totalItemCount){
// you have reached end of list, load more data probably call your database to load more data
}
@Override
public void onScrollStateChanged(AbsListView view,int scrollState) {
//blank, not using this
}
});
Hope this link may help you