gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 13:44:34 27 4
gpt4 key购买 nike

我正在使用 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)
}

最佳答案

如果您正在使用 PagingDataAdapter,searchAdapter.submitData(lifecycle, PagingData.empty())作品

关于android - 如何清除/删除页面列表适配器中的所有项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54856941/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com