看起来RealmProxy类隐藏了我的RealmObject值,但可以从proxyclass设置.
你可以看到我的模型非常简单.
public class GroupRealm extends RealmObject {
@PrimaryKey
public String id;
@Index
public String name;
public String imageUrl;
public int order;
public GroupRealm parent;
public RealmList<GroupRealm> children;
public RealmList<ContentRealm> contents;
}
Run Code Online (Sandbox Code Playgroud)
这是我设置值的方式(db是一个有效的Realm,一切都在提交正常的事务中):
GroupRealm gr = db.where(GroupRealm.class).equalTo("id",g.GroupID).findFirst();
if(gr==null){
gr = db.createObject(GroupRealm.class,g.GroupID);
}
gr.imageUrl = g.GlyphUrl;
gr.name = g.Title;
gr.order = g.OrderNum;
Run Code Online (Sandbox Code Playgroud)
下面的图片是我查询db后面的内容.(相同的变量名称在代码中不相同)
在我的android.library中,我的RealmObjects被定义为项目,我有必要的插件.
apply plugin: 'com.android.library'
apply plugin: 'realm-android'
Run Code Online (Sandbox Code Playgroud)
在项目级别,我正在设置正确的依赖项:
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath "io.realm:realm-gradle-plugin:0.90.1"
// NOTE: Do not place your application dependencies here; they belong
// in the …Run Code Online (Sandbox Code Playgroud)