我是 kotlin 和 jetpack 的新手,我被要求处理来自 PagingData 的错误(异常),我不允许使用 Flow,我只允许使用 LiveData。
这是存储库:
class GitRepoRepository(private val service: GitRepoApi) {
fun getListData(): LiveData<PagingData<GitRepo>> {
return Pager(
// Configuring how data is loaded by adding additional properties to PagingConfig
config = PagingConfig(
pageSize = 20,
enablePlaceholders = false
),
pagingSourceFactory = {
// Here we are calling the load function of the paging source which is returning a LoadResult
GitRepoPagingSource(service)
}
).liveData
}
}Run Code Online (Sandbox Code Playgroud)
这是视图模型:
class GitRepoViewModel(private val repository: GitRepoRepository) : ViewModel() {
private val …Run Code Online (Sandbox Code Playgroud)kotlin android-livedata android-jetpack kotlin-coroutines android-paging-3