问题
Is is possible to do a "IN" query with Realm in android? I mean, doing the equivalent of "SELECT X FROM X WHERE x IN (...)?
Thank you very much in advance!
回答1:
The official IN operator (since 1.2.0) works like this:
public RealmQuery<E> 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();
}
来源:https://stackoverflow.com/questions/35584661/realm-do-a-in-query-in-android