如何为Realm中的字段设置默认值?

时间:2018-05-28 06:13:04

标签: java android sqlite mobile realm

我们如何给出领域模型字段的默认值?

示例:

class Demo extends RealmObject{
    private String id; // I want to set this id to a uuid 
    private boolean isVisibile; // set this to default as true              
}

1 个答案:

答案 0 :(得分:4)

class Demo extends RealmObject{
    public Demo() {
        id = UUID.randomUuid().toString();
        isVisible = true;
    } 

    @PrimaryKey
    private String id; // I want to set this id to a uuid 
    private boolean isVisibile; // set this to default as true              
}

应该运行Realm 2.0 +