i just created a custom list view using Baseadapter.i want to implement page nation.each time i will get 10 items from server.which is the best method for implementing list view page nation.(on scroll down append 10 more to list view from server) Thanks in advance
1 Answer
You can implement an onScrollListener to your listview and pull data in onScroll() method.
list.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
final int lastItem = firstVisibleItem + visibleItemCount;
if(lastItem == totalItemCount) {
//load more data
}
}
});
There are also some libraries you could use to make it easier like Endless Adapter and Pull to refresh and Load More
2 Comments
Ando Masahashi
hey can you provide me an simple example i have doubt in how to add items in listview ?? how to initialize list view ???
Hitesh Dhamshaniya
final int lastItem = firstVisibleItem + visibleItemCount; if(lastItem == totalItemCount) { //load more data }, it is call even when list is created, I don't know why so ..