max max - 3 months ago 10
Android Question

Create RealmQuery programmatically in android

Is it possible to create "realmquery" in android dynamically and pass it to realm database?

something like this

RealmQuery<RealmModel> query;
public Model equalTo(String fildName,String value){
query=query.equalTo(fildName,value);

return (Model) this;
}

Answer

I believe you can do yourself it by wrapping your queries in utility classes, define your table names and columns as string constants and constructing your queries with the builder pattern, I suggest something like this:

    RealmUtils.query(Model.class).where(Model.FIELD1).equals("param1")
.And(MODEL.FIELD2).greaterThan(param2);

This way you can encapsulate Realm string queries and deal with strong types.