Realm query with List

后端 未结 4 1430
-上瘾入骨i
-上瘾入骨i 2020-12-19 01:37

I\'m using realm to store my data on Android. Awesome framework! Now the only problem I\'m now having is:

I got a array list strings with id\'s of Countries in my da

4条回答
  •  情深已故
    2020-12-19 02:25

    Since the Realm database has added RealmQuery.in() with the version 1.2.0

    I suggest using something like this.

    //Drinks
    public class Drinks extends RealmObject {
    @PrimaryKey
    private String id;
    private String name;
    private String countryId;
    
    //getter and setter methods
    }
    
    //Country
    public class Country extends RealmObject {
        @PrimaryKey
        private String id;
        private String name;
    
    //getter and setter methods
    }
    

    The code to use inside activity/fragments to retrieve drink list

    String[] countryIdArray = new String[] {"1","2","3"} //your string array
    RealmQuery realmQuery  = realm.where(Drinks.class)
                .in("countryId",countryIdArray);
    RealmResults drinkList = realmQuery.findAll();
    

提交回复
热议问题