1

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.

Alexander
  • 13
  • 4

2 Answers2

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.

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