Raja Jawahar
Raja Jawahar

Reputation: 6972

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);

Upvotes: 12

Views: 13902

Answers (2)

EpicPandaForce
EpicPandaForce

Reputation: 81588

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();

Upvotes: 33

Rajesh Gr
Rajesh Gr

Reputation: 71

realmResults.sort("Date", true);

Works with the Version io.realm:realm-android:0.82.1

Upvotes: 4

Related Questions