Support Topics Documentation Slack YouTube Blog

How to load next pages object when i swip up in my listview?

My table contains 50 objects per page, I want my app to retrieve the first 50 object and set them to my list view and when i swip up and reach the end of my list view my app retrieve the next page 50 objects.

Hi Peter,

Have you seen the following page in the API documentation:?
https://backendless.com/docs/android/data_data_paging.html

It describes this very scenario you’re asking about.

Regards,
Mark

It load nothing, although there is objects in the next page

Do you use the prepareNextPage() method or adjust the offset manually?

Here is my Code

 AsyncCallback<List<Movie>> callback = new AsyncCallback<List<Movie>>() {
        @Override
        public void handleResponse(List<Movie> response) {
            movies = response;

            for (com.notifyuser.peter.notify.Movie movie : response) {
                names.add(movie.getName());
            }
            loadingBar.setVisibility(View.INVISIBLE);
            moviesList.setAdapter(new MoviesListFragment.MyAdabter());
         
        }

        @Override
        public void handleFault(BackendlessFault fault) {
//                Toast.makeText(getActivity(), "Error", Toast.LENGTH_SHORT).show();
        }
    };

    int PAGESIZE =100;
    DataQueryBuilder dataQuery = DataQueryBuilder.create();
    dataQuery.setPageSize(PAGESIZE)
    .setOffset(50);

    Backendless.Data.of(com.notifyuser.peter.notify.Movie.class).find(dataQuery,callback);

    dataQuery.prepareNextPage();
    AsyncCallback<List<Movie>> callback2 = new AsyncCallback<List<Movie>>() {
        @Override
        public void handleResponse(List<Movie> response) {
            movies = response;

            for (com.notifyuser.peter.notify.Movie movie : response) {
                names.add(movie.getName());
            }
            loadingBar.setVisibility(View.INVISIBLE);
            listview2.setAdapter(new MoviesListFragment.MyAdabter());

        }

        @Override
        public void handleFault(BackendlessFault fault) {
//                Toast.makeText(getActivity(), "Error", Toast.LENGTH_SHORT).show();
        }
    };
    Backendless.Data.of(com.notifyuser.peter.notify.Movie.class).find(dataQuery,callback2);
  • There are essentially two calls happening in parallel since both of them are asynchronous.
  • When you call prepareNextPage it may happen that the first find call will use the modified dataQuery object because it happens immediately after you call first find
  • What I would recommend is to change the flow of the code where the second find is called only after you receive the result for the first find (which based on your description should happen later on anyway, that is when the user reaches the end of the list in the UI)
1 Like

You Absolutely right, Thanks it works now.

You can also try our new feature - BackendlessDataCollection.
This is an implementation of the Java Collection interface enabling to retrieve and iterate over a collection of objects stored in a Backendless data table.

Here is the brief tech documentation:
https://github.com/oleg-vyalyh/BackendlessDataCollection/blob/master/README.md

And here is the article in our blog:
https://backendless.com/data-collection-tutorial-for-android-java/

On github you can also find complete example (it shows how to use such a collection for infinity scroll taking data from the Backendless table):
https://github.com/Backendless/Android-SDK/tree/master/samples/BackendlessCollectionUsage

1 Like