Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 第3页-为什么重试页脚不调用我的PagingSource';什么是负荷法?_Android_Kotlin_Android Paging_Android Paging Library_Android Paging 3 - Fatal编程技术网

Android 第3页-为什么重试页脚不调用我的PagingSource';什么是负荷法?

Android 第3页-为什么重试页脚不调用我的PagingSource';什么是负荷法?,android,kotlin,android-paging,android-paging-library,android-paging-3,Android,Kotlin,Android Paging,Android Paging Library,Android Paging 3,我已经在我的应用程序中实现了Paging 3,使用codelab,并通过WithLoadStateHeader和footer添加了一个带有重试按钮的页脚: recycler_view_results.adapter = adapter.withLoadStateHeaderAndFooter( header = UnsplashLoadStateAdapter { adapter.retry() }, footer = UnsplashLoadStateAdapter { ada

我已经在我的应用程序中实现了Paging 3,使用codelab,并通过
WithLoadStateHeader和footer
添加了一个带有重试按钮的页脚:

recycler_view_results.adapter = adapter.withLoadStateHeaderAndFooter(
    header = UnsplashLoadStateAdapter { adapter.retry() },
    footer = UnsplashLoadStateAdapter { adapter.retry() }
)
当我在页脚的ViewHolder中单击“重试”按钮时,确实调用了
adapter.retry()
,因此那里的设置是正确的。但是,这个方法永远不会像通常那样调用我的PaginSource的
load
方法

我的分页源(我检查了
LoadResult.Error
是否在错误情况下正确返回):

有趣的是,空列表的重试按钮可以工作:

retry_button.setOnClickListener {
    adapter.retry()
    // this works
}

在我将分页依赖项从“3.0.0-alpha02”更新为“3.0.0-alpha03”后,它现在可以工作了。看起来这是图书馆里的一个bug


之后,我还发现了相应的错误报告:

在我将分页依赖项从“3.0.0-alpha02”更新为“3.0.0-alpha03”后,它现在可以工作了。看起来这是图书馆里的一个bug

之后,我还发现了相应的错误报告:

class UnsplashRepository @Inject constructor(private val unsplashApi: UnsplashApi) {

    fun getSearchResultStream(query: String): Flow<PagingData<UnsplashPhoto>> {
        return Pager(
            config = PagingConfig(
                pageSize = NETWORK_PAGE_SIZE,
                enablePlaceholders = false
            ),
            pagingSourceFactory = { UnsplashPagingSource(unsplashApi, query) }
        ).flow
    }

    companion object {
        private const val NETWORK_PAGE_SIZE = 20
    }
}
private fun searchPhotos(query: String) {
    searchJob?.cancel()
    searchJob = lifecycleScope.launch {
        viewModel.searchPhotos(query).collectLatest {
            adapter.submitData(it)
        }
    }
}
retry_button.setOnClickListener {
    adapter.retry()
    // this works
}