如何通过两个参数对 RealmObjects 列表进行排序?例如,第一个参数是 name (需要按字母顺序排序),第二个参数有点复杂,与 3 个日期相关:我有一个范围日期(例如 fromDate currentDate 和 toDate)。需要将今天发生的所有项目放在列表的开头。另外不要忘记按字母顺序排序。
您基本上是在尝试根据多个参数对
realmList
进行排序。
这是要走的路:
String[] fields = {"name","fromDate","currentDate","toDate"};
Sort[] howToSort = {Sort.ASCENDING, Sort.ASCENDING, Sort.ASCENDING, Sort.ASCENDING};
然后,您只需进行通常的领域选择即可:
realm.where(YourRealmObject.class).findAllSorted(fileds, howToSort);
正如 @EpicPandaForce 评论的那样,请查看 docs。
你可以试试这个方法..
RealmResults<Notification_History>notification_histories=realm.where(Notification_History.class).findAll().sort("notification_count");