Stack Overflow на русском Asked by Crush on December 1, 2020
Функция loadRange из 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);
}
...
}
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();
...
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP