How I can sort list of RealmObjects by two parametrs? For example first param is name (Need to sort it alphabetically), second parameter is a bit complicated and related to 3 dates: I have a range dates (for example fromDate currentDate and toDate). Need to put to the head of the list all items wich happening today. Also do not forget about alphabetically sorting.
Asked
Active
Viewed 1,088 times
1
-
2https://realm.io/docs/java/latest/api/io/realm/RealmQuery.html#findAllSorted-java.lang.String:A-io.realm.Sort:A- – EpicPandaForce Mar 16 '17 at 09:39
2 Answers
2
You're basically trying to sort a realmList
depending on multiple parameters.
Here's the way to go:
String[] fields = {"name","fromDate","currentDate","toDate"};
Sort[] howToSort = {Sort.ASCENDING, Sort.ASCENDING, Sort.ASCENDING, Sort.ASCENDING};
And then, you simply do a usual realm selection:
realm.where(YourRealmObject.class).findAllSorted(fileds, howToSort);
As @EpicPandaForce commented, please check the docs.

Anis LOUNIS aka AnixPasBesoin
- 4,765
- 5
- 32
- 61
0
You can try this way..
RealmResults<Notification_History>notification_histories=realm.where(Notification_History.class).findAll().sort("notification_count");

Muhaiminur Rahman
- 3,066
- 20
- 27