Realm on Android - How to select multiple objects by list of ids (@PrimaryKey)?

前端 未结 5 1267
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-18 21:25

I\'m building an Android app with the Realm database.

I have a RealmObject subclass called Article which has an id field (it\'s an

5条回答
  •  长发绾君心
    2021-02-18 21:53

    This is the way Realm does it since 1.2.0:

    public RealmQuery in(String fieldName, String[] values) {
        if (values == null || values.length == 0) {
            throw new IllegalArgumentException(EMPTY_VALUES);
        }
        beginGroup().equalTo(fieldName, values[0]);
        for (int i = 1; i < values.length; i++) {
            or().equalTo(fieldName, values[i]);
        }
        return endGroup();
    }
    

    Previously this is how I did it

提交回复
热议问题