Sanu
Sanu

Reputation: 455

Best method for load more item dynamically on list view on scroll in android

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

Upvotes: 1

Views: 6961

Answers (1)

Lalith Mohan
Lalith Mohan

Reputation: 3906

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

Upvotes: 5

Related Questions