问题
I've trying to integrate the architecture components in my app, viz Pagination, LiveData, ViewModel.
Room is already integrated and tested before so I can return a DataSource.Factory<Integer, DbEntity>
from my DAO class. This is my code for creating LiveData of PagedList:
PagedList.Config pagedListConfig =
(new PagedList.Config.Builder()).setEnablePlaceholders(true)
.setPrefetchDistance(5)
.setPageSize(10)
.setInitialLoadSizeHint(10)
.build();
LiveData<PagedList<DbEntity>> dbEntities = new
LivePagedListBuilder<>(DAO.getItemList(timeNow), pagedListConfig).build();
And I am observing on this livedata in my fragment class:
viewModel.dbEntities.observe(this, new Observer<PagedList<DbEntity>>() {
@Override
public void onChanged(@Nullable PagedList<DbEntity> inboxEntities) {
adapter.submitList(inboxEntities);
}
});
The problem is the list is taking too long to draw and it seems that all the items in the list (1300) are being drawn on the first go.
I verified this at two places : onChanged
is called with the PagedList size equal to 1300 and onBindViewHolder
of adapter is being called for all the positions upto 1300.
Am I doing sth wrong here?
回答1:
Got it working. It's returning correct no of elements after disabling placeholders
来源:https://stackoverflow.com/questions/50063255/pagedlist-loading-all-items-at-once