I was using FastAdapter
cause it's fun and relieves me from writing adapter classes. Here is a class:
public class ProductsModel extends AbstractItem<ProductsModel, ProductsModel.ViewHolder> {
But recently I want to use Realm
instead of SQLite
. So I wanted to do this:
public class ProductsModel extends AbstractItem<ProductsModel, ProductsModel.ViewHolder> implements RealmModel {
And before any transaction I was doing this:
RealmResults<ProductsModel> productsModels = realm.where(ProductsModel.class).findAll(); // <- this line is generating the exception
if(productsModels.size() == 0){ //no product is saved, download now
}
But getting this exception:
java.lang.IllegalArgumentException: AbstractItem is not part of the schema for this Realm
Please tell me how can I use Realm with FastAdapter.
In case you can not extend the
AbstractItem
theFastAdapter
allows you to simply implement theIItem
interface. You will have to implement the functions you already know + the ones which would normally be implemented by theAbstractItem
Here is a sample item:
To simplify it, I have removed comments, and unnecessary setters. A full sample can be found in the
FastAdapter
s sample source here: https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/items/RealmSampleUserItem.javaIn case you are interested, here you can find the default
AbstractItem
implementation: https://github.com/mikepenz/FastAdapter/blob/develop/library-core/src/main/java/com/mikepenz/fastadapter/items/AbstractItem.java