- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我从分页 2 迁移到分页 3。我尝试将分页 2 的 ItemKeyedDataSource 实现到分页库 3。但我面临的问题是,在加载的两个连续页面中,相同的值(currentJodId)作为 nextkey 传递。在该应用程序崩溃之后。但是如果我在数据源中添加“keyReuseSupported = true”,应用程序不会崩溃。但它开始调用与 nextkey 相同的项目 ID。JobSliderRestApi.kt
@GET("job/list/slides")
fun getDetailOfSelectedJob(
@Query("current_job") currentJodId: Int?,
@Query("limit") jobLimit: Int?,
@Query("search_in") fetchType: String?
): Single<Response<JobViewResponse>>
JobViewResponse.kt
data class JobViewResponse(
@SerializedName("data") val data: ArrayList<JobDetail>?
) : BaseResponse()
JobDetail.kt
data class JobDetail(
@SerializedName("job_id") val jobId: Int,
@SerializedName("tuition_type") val jobType: String?,
@SerializedName("class_image") val jobImage: String,
@SerializedName("salary") val salary: String,
@SerializedName("no_of_student") val noOfStudent: Int,
@SerializedName("student_gender") val studentGender: String,
@SerializedName("tutor_gender") val preferredTutor: String,
@SerializedName("days_per_week") val daysPerWeek: String?,
@SerializedName("other_req") val otherReq: String?,
@SerializedName("latitude") val latitude: Double?,
@SerializedName("longitude") val longitude: Double?,
@SerializedName("area") val area: String,
@SerializedName("tutoring_time") val tutoringTime: String?,
@SerializedName("posted_date") val postedDate: String?,
@SerializedName("subjects") val subjects: String,
@SerializedName("title") val title: String
)
JodSliderDataSource.kt
class JodSliderDataSource @Inject constructor(
private val jobSliderRestApi: JobSliderRestApi
): RxPagingSource<Int, JobDetail>() {
// override val keyReuseSupported = true
@ExperimentalPagingApi
override fun getRefreshKey(state: PagingState<Int, JobDetail>): Int? {
return state.anchorPosition?.let {
state.closestItemToPosition(it)?.jobId
}
}
override fun loadSingle(params: LoadParams<Int>): Single<LoadResult<Int, JobDetail>> {
return jobSliderRestApi.getDetailOfSelectedJob(42673, 2, "next").toSingle()
.subscribeOn(Schedulers.io())
.map { jobResponse -> toLoadResult(jobResponse.data) }
.onErrorReturn { LoadResult.Error(it) }
}
private fun toLoadResult(data: ArrayList<JobDetail>): LoadResult<Int, JobDetail> {
return LoadResult.Page(data = data, prevKey = null, nextKey = data.lastOrNull()?.jobId)
}
}
最佳答案
我遇到了同样的错误,这对我有用。在 JodSliderDataSource 类(class), toLoadResult 方法,设置 nextKey 通过从响应数据中获取页码并加一来获取参数值。
private fun toLoadResult(
data: ArrayList<JobDetail>
): LoadResult<Int, JobDetail> {
return LoadResult.Page(
data = data,
prevKey = null,
nextKey = data.lastOrNull()?.jobId + 1 // Add one to the page number here.
)
}
关于android-studio - 相同的值作为 nextKey 在从 Paging Library 3 Android 中的 PagingSource 加载的两个连续页面中传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63870064/
项目中不起作用的元素 我检查数据是否不为空,并在 fragment 中执行默认的 submitList。 顺便说一句,这里是文档的链接 搜索分页源 这些日志甚至没有显示 class Searc
我从 Paging 2 迁移到 Paging 3 库,现在我使用 PagingSource从服务器加载数据页面。但我无法理解 getRefreshKey必须在那里重写的方法。我找到了一些代码示例,如何
我正在使用最新的 Jetpack 库。 分页3版本:3.0.0-alpha05房间版:2.3.0-alpha02我的实体有 Long as PrimaryKey和 Room 可以生成 PagingSo
谷歌最近宣布了新的 Paging 3 库、Kotlin-first 库、支持协程和 Flow 等。 我玩过codelab他们提供但似乎还没有任何测试支持,我还检查了documentation .他们没
我的 PagingSource 加载一些数据。文档建议像这样捕获异常,以便将来处理 LoadResult.Error。 override suspend fun load(params: LoadP
我正在尝试使用 GraphQL Relay spec 实现基于光标的分页(基于 Android Paging Library 3 ) ,但不知道如何实现 getRefreshKey . 这是我尝试过的
由于我目前正在使用自定义数据库(而不是 Room)进行项目,因此我正在测试我们是否可以在项目中使用 Paging 3 库。 但是,我遇到了一个问题,如果您更改数据并因此使分页源无效,则列表的重新创建是
我的问题实际上很笼统。我想知道如何对 进行单元测试房间 道 返回 的查询寻呼源 来自 寻呼 3 . 我有一个 房间 道 询问: @Query("SELECT * FROM database")
我从分页 2 迁移到分页 3。我尝试将分页 2 的 ItemKeyedDataSource 实现到分页库 3。但我面临的问题是,在加载的两个连续页面中,相同的值(currentJodId)作为 nex
我试图为新的 Paging 3 库模仿 Google 的 codelab,当我尝试让 Room DAO 方法返回 PagingSource 时遇到以下错误: D:\Programming\Androi
我是一名优秀的程序员,十分优秀!