Load more data from database and show listview in android browser.
2 answers
What you are looking for is called EndlessScrollListener . You will need to extend the class EndlessScrollListener
and implement the method onLoadMore
.
public class MyEndlessScrollListener extends EndlessScrollListener {
@Override
public void onLoadMore(int page, int totalItemsCount) {
loadData(page);
}
}
And set the listener to listView:
listView.setOnScrollListener(new EndlessScrollListener());
You can use other constructors if you want EndlessScrollListener
.
+2
source to share
This is what I used to load more data at the end of the list.
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 can help you
0
source to share