'Realm Android run query of if field contain value in a List<String>
This is My RealmObject:
public class Channel extends RealmObject{
private String id = "";
private String name = "";
...
I am trying to construct a query where each string in a list of string contains (not equal) to the "name" field. I am aware I can use the in() method with a ArrayList, but the in() method validate if the string EQUALS and rather need CONTAINS.
I have tried the following:
realm.where(Channel.class).rawPredicate("name CONTAINS[c] $0",list.toArray()).findAll()This perform the query only on the first String in "list"realm.where(Channel.class).in("name", list.toArray()).findAll()is performing there search only if the field "name" EQUALS to any of the Strings in the list, where I need it to search if the field CONTAINS any of the values in the List of Strings
Any ideas of how to use a method just like in() but that will compare if the string equals or contain the field value?
Thanks
Solution 1:[1]
try this
RealmQuery<Channel> tasksQuery = realm.where(Channel.class).beginGroup();
for(String name: names){
tasksQuery.equalTo("name", name)
}
tasksQuery.endGroup().findAll()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Zen |
