【发布时间】:2017-05-31 04:07:15
【问题描述】:
我使用的是FastAdapter,因为它很有趣,让我不必编写适配器类。这是一个类:
public class ProductsModel extends AbstractItem<ProductsModel, ProductsModel.ViewHolder> {
但最近我想使用Realm 而不是SQLite。所以我想这样做:
public class ProductsModel extends AbstractItem<ProductsModel, ProductsModel.ViewHolder> implements RealmModel {
在任何交易之前,我都是这样做的:
RealmResults<ProductsModel> productsModels = realm.where(ProductsModel.class).findAll(); // <- this line is generating the exception
if(productsModels.size() == 0){ //no product is saved, download now
}
但是得到这个异常:
java.lang.IllegalArgumentException: AbstractItem is not part of the schema for this Realm
请告诉我如何将 Realm 与 FastAdapter 一起使用。
【问题讨论】:
-
我仍然使用 Realm 和 FastAdapter,但是由于您上面的代码
ProductsModel不是 Realm 中的模型,它是一个 Item 代表适配器中的项目。所以它不能implements RealmModel。只是Item,你需要按照fastadapter的例子来做。 -
谢谢,您能分享任何示例/教程吗?我没有收到this
-
你可以从github.com/mikepenz/FastAdapter/tree/develop/app得到它。获取所有并构建它。
-
好的,看到
RealmSampleUserItem。我认为这会奏效
标签: android realm realm-mobile-platform fastadapter