大家好,我使用 Android Jetpack Paging 库 3,我正在创建一个实现网络 + 数据库场景的新闻应用程序,我正在关注 google 的 Codelab https://codelabs.developers.google.com/codelabs/android-paging,我几乎就像在 Codelab 中一样,我几乎匹配了示例中显示的所有操作https://github.com/android/architecture-components-samples/tree/main/PagingWithNetworkSample。
它几乎按其应有的方式工作......但我的后端响应是页面键控的,我的意思是响应带有新闻列表和下一页网址,远程中介获取数据,填充数据库,设置存储库,设置视图模型。 ..
问题是:当recyclerview加载数据时,会发生以下情况:recyclerview闪烁、项目跳转、被删除、再次添加等等。我不知道为什么 recyclerview 或其 itemanimator 的行为如此,看起来如此丑陋和故障。更重要的是,当我滚动到列表末尾时,会获取新项目,并且再次发生故障和跳跃效果。
如果您能帮助我,我将非常感激,我已经坐了三天了,提前非常感谢您。这是我的代码片段:
@Entity(tableName = "blogs")
data class Blog(
@PrimaryKey(autoGenerate = true)
val databaseid:Int,
@field:SerializedName("id")
val id: Int,
@field:SerializedName("title")
val title: String,
@field:SerializedName("image")
val image: String,
@field:SerializedName("date")
val date: String,
@field:SerializedName("share_link")
val shareLink: String,
@field:SerializedName("status")
val status: Int,
@field:SerializedName("url")
val url: String
) {
var categoryId: Int? = null
var tagId: Int? = null
}
Run Code Online (Sandbox Code Playgroud)
这是 DAO
@Insert(onConflict …
Run Code Online (Sandbox Code Playgroud) android android-architecture-components android-paging android-paging-library android-paging-3