【发布时间】:2019-02-23 17:50:18
【问题描述】:
我正在尝试使用新的 Paging Library 和 Room 作为数据库,但我遇到了一个问题,数据库返回的 PagedList 不应该是发送到 UI 的同一个列表,我map 一些实体在向用户展示之前,在此map 操作期间,我更改了列表大小(添加项目),显然Paging Library 不支持这种操作,因为当我尝试运行应用程序时,我得到这个异常:
Caused by: java.lang.IllegalStateException: Invalid Function 'function_name' changed return size. This is not supported.
看分页库源码你看到这个方法:
static <A, B> List<B> convert(Function<List<A>, List<B>> function, List<A> source) {
List<B> dest = function.apply(source);
if (dest.size() != source.size()) {
throw new IllegalStateException("Invalid Function " + function
+ " changed return size. This is not supported.");
}
return dest;
}
在使用之前向PagedList 添加动态项目时,是否有解决方法或需要处理的问题?
这就是我正在做的事情
道
@Query("SELECT * FROM table_name")
fun getItems(): DataSource.Factory<Int, Item>
本地来源
fun getItems(): DataSource.Factory<Int, Item> {
return database.dao().getItems()
.mapByPage { map(it) } // This map operation changes the list size
}
【问题讨论】:
-
我遇到了像你这样的问题。如果您找到任何解决方案,请回答您的问题
-
我为此在 Android 错误跟踪器上提交了一个问题。如果这对您有影响,请加注星标issuetracker.google.com/issues/142890117
标签: android android-room android-architecture-components android-paging