1

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 1

5

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

Sign up to request clarification or add additional context in comments.

2 Comments

hey can you provide me an simple example i have doubt in how to add items in listview ?? how to initialize list view ???
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 ..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.