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