Reputation: 177
I have set the page size to 10, The page size in the observer is giving the right size, but all the items from the database(ROOM) is getting loaded to the view holder
The boundary call back onItemAtEndLoaded is getting called with the last item in the database.
Here is my configuration:
public LiveData<PagedList<Design>> getDesignList(List<String> types, String idCode){
DataSource.Factory<Integer, Design> factory = mRepository.getDesigns(types, idCode);
PagedList.Config pagedListConfig =
(new PagedList.Config.Builder())
.setEnablePlaceholders(false)
.setInitialLoadSizeHint(10)
.setPageSize(10)
.build();
return new LivePagedListBuilder<>(factory, pagedListConfig)
.setBoundaryCallback(**boundCallBack**)
.setFetchExecutor(mRepository.mIoExecutor)
.build();
}
Repository(mRepository.getDesigns):
public DataSource.Factory<Integer, Design> getDesigns(List<String> types, String idCode) {
return designDao.getDesigns(types,idCode);
}
Dao:(getDesigns)
@Query("SELECT * FROM Design WHERE design_type IN (:types) AND id=:idCode ORDER BY design_id ASC")
DataSource.Factory<Integer, Design> getDesigns(List<String> types, String idCode);
boundary callback(boundCallBack):
public class BoundCall extends PagedList.BoundaryCallback<Design> {
public BoundCall() {
super();
}
@Override
public void onZeroItemsLoaded() {
super.onZeroItemsLoaded();
fetchFromNetwork(null);
Log.e("load", "men-onZeroItemsLoaded");
}
@Override
public void onItemAtFrontLoaded(@NonNull Design itemAtFront) {
super.onItemAtFrontLoaded(itemAtFront);
Log.e("load", "men-onItemAtFrontLoaded: " + itemAtFront.getDesignName());
}
@Override
public void onItemAtEndLoaded(@NonNull Design itemAtEnd) {
super.onItemAtEndLoaded(itemAtEnd);
fetchFromNetwork(itemAtEnd);
Log.e("load", "men-onItemAtEndLoaded: " + itemAtEnd.getDesignName());
}
}
The observer:
designAdapter = new DesignAdapter(this);
menClothRv.setAdapter(designAdapter);
// Observer to the changed list in the
obs = new Observer<PagedList<Design>>(){
@Override
public void onChanged(PagedList<Design> designs) { //the pagesize is 10 here, but all items are loaded
if(!designs.isEmpty())
designAdapter.submitList(designs);
}
};
Unable to figure it out: I even referred to this as well: pagedList loading
Upvotes: 1
Views: 665
Reputation: 199805
It sounds like your RecyclerView
is within another scrolling view such as a NestedScrollingView
, causing the RecyclerView
to lay out all of its items.
You should always avoid nesting containers that scroll in the same direction (i.e., both vertically) and instead separate the two, either using the header functionality built into Paging 3 or ConcatAdapter
to build separate headers and footers that will scroll along with your other content.
Upvotes: 6