我正在使用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)
}
提交null清除当前加载的页面列表
productSearchResultItemAdapter.submitList(null)
在Java中:
无效之前,请清除您的列表数据项。就像我们以简单的方式所做的一样: