Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Realm java sort with multiple fields

I'm sorting like this:

RealmResults<Show> shows = realm.where(Show.class).findAll();
shows.sort("venueTitle", RealmResults.SORT_ORDER_ASCENDING);

How can I sort by multiple properties? Adding another sort line just resets the order of the results entirely.

like image 945
codeman Avatar asked Jan 21 '15 16:01

codeman


2 Answers

Looks like they just added this in 0.77. I was using 0.76. Here's the Github issue: https://github.com/realm/realm-java/issues/648

and here's the API reference: http://realm.io/docs/java/0.77.0/api/

public void sort(java.lang.String[] fieldNames,
    boolean[] sortAscending)
like image 170
codeman Avatar answered Nov 16 '22 12:11

codeman


try below code

 public RealmResults getSortedList(Class aClass) {
        String []fieldNames={"field1","field2"};
        Sort sort[]={Sort.ASCENDING,Sort.ASCENDING};
        return realm.where(YourClass.class).findAllSorted(fieldNames,sort);
    }
like image 37
Amol Suryawanshi Avatar answered Nov 16 '22 13:11

Amol Suryawanshi