更新:
レルム1.2.0複数の値と比較するためにRealmQuery.in()
が追加されました。 The documentationは利用可能なすべてのオーバーロードを詳細に示します。
public RealmQuery<E> in(String fieldName, Integer[] values)
オリジナルの答え:This oneは、私たちのIDがInteger
のであれば、我々が使用できる方法である@ChristianMelchiorから
答えIDのリストが空の場合、すべての記事を返します。私はそれが空のRealmResults<Article>
を返すようにします。それが私がやったことです。
Set<Integer> articleIds = this.getArticleIds();
RealmQuery<Article> query = realm.where(Article.class);
if (articleIds.size() == 0) {
// We want to return an empty list if the list of ids is empty.
// Just search for an id that does not exist.
query = query.equalTo("id", -30000);
} else {
int i = 0;
for (int id : articleIds) {
// The or() operator requires left hand and right hand elements.
// If articleIds had only one element then it would crash with
// "Missing right-hand side of OR"
if (i++ > 0) {
query = query.or();
}
query = query.equalTo("id", id);
}
}
return query.findAll();
それをやった方法です。http://stackoverflow.com/a/32068221/2413303 – EpicPandaForce
@EpicPandaForceはいまったく同じです。投稿する前にたくさん検索しました。私の解決策(下記)は、IDのリストが空である場合を処理します。 –
質問のタイトルに 'list'という単語を追加しました。たぶん、目標を見つけて理解するのが簡単になるでしょう。 –