Reputation: 1121
I'm having trouble sorting my database alphabetically. I assume I need to sort the database here:
public static Cursor getAllRecords() {
return db.query(DATABASE_TABLE, new String[] { KEY_ROWID, KEY_ITEM},
null, null, null, null, null, null);
}
I've tried replacing the last null
with " DESC" which didn't work.
Am I doing this in the wrong spot?
Upvotes: 1
Views: 1016
Reputation: 23638
Try this -
return db.query(DATABASE_TABLE, new String[] { KEY_ROWID, KEY_ITEM}, null, null, null, null, KEY_ITEM+ " ASC");
or
return db.query(DATABASE_TABLE, new String[] { KEY_ROWID, KEY_ITEM}, null, null, null, null, KEY_ITEM+ " DESC");
Upvotes: 1
Reputation: 14226
Use something like KEY_ITEM + " DESC"
for the orderBy
parameter:
public static Cursor getAllRecords() {
return db.query(DATABASE_TABLE, new String[] { KEY_ROWID, KEY_ITEM},
null, null, null, null, KEY_ITEM + " DESC"); // note the missing last null for 'limit'
}
Upvotes: 2