AnswerBun.com

Проблема с Paging Library

Stack Overflow на русском Asked by Crush on December 1, 2020

Функция loadRange из data source выполняется только один раз, хотя в нем есть еще данные.

Data source

public class PhotoDataSource extends PositionalDataSource<GalleryItem> {
    List<GalleryItem> galleryItems;

    public PhotoDataSource(List<GalleryItem> galleryItems) {
        this.galleryItems = galleryItems;
    }

    @Override
    public void loadInitial(@NonNull LoadInitialParams params,
                            @NonNull LoadInitialCallback<GalleryItem> callback) {
        Log.d("PhotoDataSource", "loadInitial, requestedStartPosition = "
                + params.requestedStartPosition
                + ", requestedLoadSize = " + params.requestedLoadSize);
        List<GalleryItem> result = galleryItems.subList(
                params.requestedStartPosition, params.requestedLoadSize);
        callback.onResult(result, 0);
    }

    @Override
    public void loadRange(@NonNull LoadRangeParams params,
                          @NonNull LoadRangeCallback<GalleryItem> callback) {
        Log.d("PhotoDataSource", "loadRange, startPosition = "
                + params.startPosition + ", loadSize = " + params.loadSize);
        List<GalleryItem> result = safeSubList(galleryItems, params.startPosition,
                params.startPosition + params.loadSize);
        callback.onResult(result);
    }
...
}

Инициализация paged list

PhotoDataSource dataSource = new PhotoDataSource(galleryItems);
        PagedList.Config config = new PagedList.Config.Builder()
                .setEnablePlaceholders(false)
                .setPageSize(10)
                .build();
        PagedList<GalleryItem> pagedList = new PagedList.Builder<>(dataSource, config)
                .setNotifyExecutor(new Executor() {
                    @Override
                    public void execute(Runnable runnable) {

                    }
                })
                .setFetchExecutor(Executors.newSingleThreadExecutor())
                .build();
...

Add your own answers!

Related Questions

Неверный формат даты в SQL

1  Asked on December 28, 2021

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir