I'm trying to do:
mRealm
.where(Contact.class)
.equalTo(Contact.NAME, text, Case.INSENSITIVE)
.findAllSortedAsync(Contact.NAME, Sort.ASCENDING);
Result: Expected result not met.
mRealm
.where(Contact.class)
.contains(Contact.NAME, text, Case.INSENSITIVE)
.findAllSortedAsync(Contact.NAME, Sort.ASCENDING);
Result: Expected result not met.
Expected result:
mRealm
.where(Contact.class)
.like(Contact.NAME, text, Case.INSENSITIVE)
.findAllSortedAsync(Contact.NAME, Sort.ASCENDING);
NEW ANSWER:
Realm 2.3.0+:
public RealmQuery<E> like(String fieldName, String value, Case casing)
Condition that the value of field matches with the specified substring, with wildcards:
'*'
matches[0, n]
unicode chars
'?'
matches a single unicode char.Parameters:
fieldName
- the field to compare.
value
- the wildcard string.
casing
- how to handle casing. Setting this toCase.INSENSITIVE
only works for Latin-1 characters.Returns: the query object.
Throws: IllegalArgumentException - if one or more arguments do not match class or field type.
OLD ANSWER:
mRealm
.where(Contact.class)
.contains(Contact.NAME, text, Case.INSENSITIVE)
.findAllSortedAsync(Contact.NAME, Sort.ASCENDING);
This should work, but you will receive a callback to an appended RealmChangeListener when the actual async query is completed.
A RealmRecyclerViewAdapter
does this automatically from https://github.com/realm/realm-android-adapters.
mRealm
.where(Contact.class)
.like(Contact.NAME, text, Case.INSENSITIVE)
.findAllSortedAsync(Contact.NAME, Sort.ASCENDING);
This piece of code works for me .
Realm realm=Realm.getDefaultinstance();
RealmResults<Item> reaaa = realm.where(Item.class).like("name",query,Case.INSENSITIVE).findAll();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With