问题描述:

Is it possible to add a filter like prioritization in RealmResult

ex.

RealmResult<Persons> persons

Id | Name

1 Eleo

2 Cath

8 Chris

9 Emman

5 John

I want to prioritize "John" then "Emman" then sort by "Id"

RealmResult<Persons> persons

Id | Name

5 John

9 Emman

1 Eleo

2 Cath

8 Chris

Is it possible to achieve this kind of sorting?

RealResult <Persons> persons_list = realm.where(Persons.class).findAll().sort("id").priority("id",int[]{5,9});

网友答案:

I got an Idea mention by @Christian maybe I'll create a column that contains index. .that default is null and if I want to prioritize I have to get the non null and increment the result and set it as index

example

Id | Name | Index
5   John   (null)
9   Emman  (null)
1   Eleo   (null)
2   Cath   (null)
8   Chris  (null)

int get_non_null_index = realm.where(Persons.class).isNotNull("Index").findAll().size();
get_non_null_index += 1
john.setIndex(get_non_null_index);
get_non_null_index += 1
emmain.setIndex(get_non_null_index);

findAllSorted("Index", Sort.DESC)

相关阅读:
Top