@Override public void onScroll( AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { boolean loadMoreRestaurants = firstVisibleItem + visibleItemCount >= totalItemCount; boolean moreDataAvailable = (nextPageToken != null && !nextPageToken.equalsIgnoreCase("")); if (loadMoreRestaurants && moreDataAvailable && !isLoadingMoreRestaurants) { Log.v( LOG_TAG, "Load more restaurants request send and more restaurants are available. Loading."); // Show the progress bar onProgressBarShowRequestListener.showProgressBar(); isLoadingMoreRestaurants = true; // The app is requesting for more data and there is more data available. // Requesting them Toast.makeText(context, R.string.loading_new_restaurants, Toast.LENGTH_LONG).show(); session.getRestaurantsNearbyNextPage( nextPageToken, new RequestRestaurantsCallback() { @Override public void done( List<Restaurant> newRestaurants, String newNextPageToken, String errorMessage, RequestStatus requestStatus) { isLoadingMoreRestaurants = false; // Disable the progress bar onProgressBarShowRequestListener.hidePorgressBar(); if (!ErrorHandler.isError(requestStatus)) { nextPageToken = newNextPageToken; restaurantListAdapter.addMoreRestaurants(newRestaurants); } else { Toast.makeText(context, errorMessage, Toast.LENGTH_LONG).show(); // Remove the next page token saved nextPageToken = null; // If there is any error about Internet connection but the list of // restaurants has been retrieved offLine, reset the list if (requestStatus == RequestStatus.ERROR_REQUEST_NOK_HTTP_NO_CONNECTION && newRestaurants != null) { showRestaurantList(newRestaurants); } } } }); } }