首页 > 解决方案 > 使用分页库进行过滤/排序时如何再次显示加载程序

问题描述

enter code here

//constructor
   ProductsViewModel(String seoUnique) {
      // getting our data source factory
      ProductsDataSourceFactory productsDataSourceFactory = new ProductsDataSourceFactory(seoUnique, 
"");

    // getting the live data source from data source factory
    networkState = Transformations.switchMap(productsDataSourceFactory.getItemLiveDataSource(),
            ProductsDataSource::getProgressLiveStatus);

    // getting the total items from data source factory
    total = Transformations.switchMap(productsDataSourceFactory.getItemLiveDataSource(),
            ProductsDataSource::getLiveTotal);

    // Getting PagedList config
    PagedList.Config pagedListConfig =
            (new PagedList.Config.Builder())
                    .setEnablePlaceholders(false)
                    .setPageSize(ProductsDataSource.PAGE_SIZE).build();

    // Building the paged list
    itemPagedList = Transformations.switchMap(filter, input -> {
        if (input == null || input.isEmpty()) {
            return (new LivePagedListBuilder(productsDataSourceFactory, pagedListConfig)).build();
        } else {
            return (new LivePagedListBuilder(new ProductsDataSourceFactory(seoUnique, input), pagedListConfig)).build();
        }
    });
}

加载器显示 ProductsDataSourceFactory 构造函数实例,但是当过滤器不为空时,它没有显示任何加载器,因为过滤器中我不使用 productsDataSourceFactory 构造函数实例。

请给出任何解决方案

提前致谢。

标签: javaandroidmvvmandroid-livedatamutablelivedata

解决方案


推荐阅读