如何使用Paging 3库更新单个项目 [英] How to update single item using Paging 3 library

查看:198
本文介绍了如何使用Paging 3库更新单个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找到一种使用Paging 3库中的PagingAdapter更新回收者视图中单个项目的方法.我发现PagingAdapter.refresh()方法只有一种方法.但是此方法强制从网络加载所有列表.有人知道如何在不从网络加载所有页面的情况下实现它吗?

I am trying to find a way to update single item in recycler view using PagingAdapter from Paging 3 library. I have found only one way with PagingAdapter.refresh() method. But this method force to load all list from network. Does anybody know how to implement it without loading all pages from network?

推荐答案

当前,更新后备数据集的唯一方法是使列表无效并重新加载列表.对于正在使用缓存层的分层源(无论是在房间还是在内存中的db中),这通常是一种便宜的可接受的选择,尽管正在进行中以支持更精细的更新(请参见

Currently, the only way to update the backing dataset is to invalidate and reload the list. This is generally an acceptably cheap option for layered sources that use a cached layer (either in db such as room or in memory), although there is ongoing work to support more granular updates (see https://issuetracker.google.com/160232968).

就目前的分层源而言,您需要将网络调用移至 RemoteMediator 中,您可以在 Pager 的构造函数中注册该网络调用,并缓存您的网络可以获取与Room一样的数据库(可以为您生成 PagingSource 实现),也可以自己编写一个内存中的数据库.

In terms of layered source for now, you'll need to move your network calls into a RemoteMediator which you can register in Pager's constructor, and cache your network fetches into either a DB like with Room (which can generate a PagingSource implementation for you), or write an in-memory one yourself.

codelab

The codelab and DAC docs are a great resource for this, and have code samples to guide you!

这篇关于如何使用Paging 3库更新单个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆