How to sort the data from the database before outputting it to the TextView Data is output using the adapter

when using "DESC" there is no result for some reason

code example

insert ===========

public long createNote(String title, String body, String date) { ContentValues initialValues = new ContentValues(); initialValues.put(KEY_TITLE, title); initialValues.put(KEY_BODY, body); initialValues.put(KEY_DATE, date); return mDb.insert(DATABASE_TABLE, null, initialValues); } 

============= and this extract

  <i> String orderBy = "DESC"; return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE, KEY_BODY,KEY_DATE}, null, null, null, null, orderBy); </i> 

But "DESC" for some reason does not sort

    1 answer 1

    According to en-SO , the query should clarify which column should be erased by adding it before specifying the sorting method:

    those. instead

    String orderBy = "DESC";

    need to

     String orderBy = yourColumn + " DESC"; 
    • if I apply String orderBy = KEY_ROWID + "DESC"; I’m getting started when Unfortunately, NoteList has stoped - mtb
    • @mtb, you caught some mistake. Without specifying its type, no one can help you. Check that you have substituted the exact name of the column. - JuriySPb
    • KEY_ROWID contains _id - but this is why it does not work strangely - mtb
    • @mtb, Well, maybe it should be surrounded with some kind of quotes ... Something like "`_id` DESC" - YuriySPb
    • one
      In your example, this is the case, but this is not the case (first comment under your answer) - pavlofff