如何清除/删除页面列表适配器中的所有项目

问题描述 投票:2回答:3

我正在使用android分页库显示搜索结果项,有什么方法可以清除/删除所有已加载的结果项,在活动的分页列表上调用Invalidate刷新列表,而不清除/删除项

In Activity: 
 fun clearSearchResult() {
        if (productSearchResultItemAdapter.itemCount > 0) {
            viewModel.invalidateResultList()
        }
    }


In ViewModel
 private fun searchProductByTerm(searchTerm: String): Listing<Item> {
        sourceFactory = ProductSearchItemDataSourceFactory(productSearchUC, compositeDisposable, searchTerm, resourceResolver)

        val livePagedList = LivePagedListBuilder(sourceFactory, pagedListConfig)
                //The executor used to fetch additional pages from the DataSource
                .setFetchExecutor(getNetworkExecutor())
                .build()

        return Listing(
                pagedList = livePagedList,
                networkState = switchMap(sourceFactory.sourceLiveData) {
                    it.networkState
                },
                retry = {
                    sourceFactory.sourceLiveData.value?.retryAllFailed()
                }
        )

    }


    fun invalidateResultList() {
        sourceFactory?.sourceLiveData?.value?.invalidate()
    }

private val productSearchName = MutableLiveData<String>()
    private val repoResult = map(productSearchName) {
        searchProductByTerm(it)
    }
android android-architecture-components android-paging-library
3个回答
2
投票

提交null清除当前加载的页面列表

  productSearchResultItemAdapter.submitList(null)

0
投票

在Java中:


-1
投票

无效之前,请清除您的列表数据项。就像我们以简单的方式所做的一样:

© www.soinside.com 2019 - 2024. All rights reserved.