Realm Android run query of if field contain value in a List<String>

769 Views Asked by At

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:

  1. realm.where(Channel.class).rawPredicate("name CONTAINS[c] $0",list.toArray()).findAll() This perform the query only on the first String in "list"
  2. 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

1

There are 1 best solutions below

0
Zen On

try this

RealmQuery<Channel> tasksQuery = realm.where(Channel.class).beginGroup();
for(String name: names){
    tasksQuery.equalTo("name", name)
}
tasksQuery.endGroup().findAll()