Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sort the RealmResults with recents dates?

I have around 20 rows in RealmResults and need to sort the list with recent dates

RealmConfiguration realmConfig = new RealmConfiguration.Builder(getActivity()).build();
Realm realm = Realm.getInstance(realmConfig);

Like below

RealmResults<MyTable> List = realm.where(MyTable.class).findAll().sort("date",SORT.DESCENDING);
like image 643
Raja Jawahar Avatar asked Apr 13 '16 07:04

Raja Jawahar


1 Answers

It's really just the following.

RealmResults<MyTable> list = realm.where(MyTable.class)
                                .findAllSorted("date",Sort.DESCENDING);

And since 4.3.x:

RealmResults<MyTable> list = realm.where(MyTable.class)
                      .sort("date",Sort.DESCENDING)
                      .findAll();
like image 172
EpicPandaForce Avatar answered Oct 26 '22 21:10

EpicPandaForce