pagedList一次加载所有项目 [英] pagedList loading all items at once

查看:71
本文介绍了pagedList一次加载所有项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将架构组件集成到我的应用程序中,即分页,LiveData和ViewModel.Room已经被集成和测试过,因此我可以从我的DAO类返回 DataSource.Factory< Integer,DbEntity> .这是我用于创建PagedList的LiveData的代码:

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);
            }
        });

问题在于列表绘制时间太长,而且列表(1300)中的所有项目似乎都是在第一次绘制时绘制的.

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.

我在两个地方验证了这一点:调用了 onChanged ,其PagedList大小等于1300,并且调用了适配器的 onBindViewHolder ,直到1300为止的所有位置.

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.

我在这里做错了吗?

推荐答案

使其正常运行.禁用占位符后,它返回正确的元素个数

Got it working. It's returning correct no of elements after disabling placeholders

这篇关于pagedList一次加载所有项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆