pagedList loading all items at once

情到浓时终转凉″ 提交于 2021-01-27 05:40:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!