Skip to content Skip to sidebar Skip to footer

Listview Is Working Incorrectly With Implementing A Load More Function

So, I have a listview and getting the data for it from an external database. I would like to have 20 items the first time, then if the user scrolls down it loads another 20 and so

Solution 1:

You can set a OnScrollListener on your ListView. In the onScroll() method, check if:

firstVisible + visibleItemCount = totalItemCount

If this condition is satisfied, you can load more items from the database, reinitialize the adapter with the updated list of items.

listView.setOnScrollListener(new OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {}

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if ((firstVisibleItem + visibleItemCount) == totalItemCount) {

                // add 20 more items to the list and reinitialize the adapter

            } 
        }
    });
}

Post a Comment for "Listview Is Working Incorrectly With Implementing A Load More Function"