dimanche 6 mars 2016

android sqlite sorting/ ORDER BY query

I have combine list which contains red color or not. I want to sort my result as below -

If color is not red then display result Alphabetically. (in continuation of list) ---> If color is red then display rest of element Alphabetically.

I am expecting below result :

// If color is not red then display result Alphabetically

orange A (color is not red & alphabetically order)

blue B (color is not red & alphabetically order)

white C (color is not red & alphabetically order)

black D (color is not red & alphabetically order)

//(in continuation of list) ---> If color is red then display rest of element Alphabetically

red A (color is red & alphabetically order)

red B (color is red & alphabetically order)

red C (color is red & alphabetically order)

To achieve this, i am trying below query :

public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    switch (id) {

        case SORT_BY_ALPHABETICALLY:

            String orderAlphabetically = BY_NAME + " ASC, "
                + BY_COLOR + " ASC";

            return new CursorLoader(ctx,
                    URI,
                    null,
                    null,
                    null,
                    orderAlphabetically);

but above query is not giving expected result.

Aucun commentaire:

Enregistrer un commentaire