代码之家  ›  专栏  ›  技术社区  ›  guness Manas

在领域中,如何从RealmList(Android)查询

  •  3
  • guness Manas  · 技术社区  · 9 年前

    查看以下课程:

    class Person{
        int id;
        String name;
        RealmList<Mail> mails;
        ...
    }
    
    class Mail{
        int id;
        String content;
        ...
    }
    

    我有一个 Person 对象(即: mPerson )我正在访问所有 Mail 对象 mPerson.getMails() .直到这里一切都很好。


    问题来了 :是否可以查询返回的列表,例如 findAllSortedAsync() ?

    2 回复  |  直到 9 年前
        1
  •  12
  •   beeender    9 年前

    只需使用 RealmList.where() 以创建查询。您可以找到文档 here

    例如: RealmList<Mail> mails = person.getMails(); RealmResults<Mail> results = mails.where().equalTo("id", 1).findAllSortedAsync();

        2
  •  0
  •   Ashish Dwivedi    7 年前
        RealmResults<Contact> contacts = mRealm.where(Contact.class).findAll();
    
        int size = contacts.size();
        for (int i = 0;i<size;i++){
            Contact contact = contacts.get(i);
            RealmList<EMail> eMails = contact.emails;
        }