I am filling a ListView with data from my SQLite Database using a SimpleCursorAdapter. The data is fine but the latest entry is always inserted at the bottom of the ListView and I want to have it at the top.
I already found this post but I don`t know how to import this to my project. At the moment my SQL query looks like this:
public Cursor fetchAllProjects() {
Cursor mCursor = mDb.query(SQLITE_TABLE, new String[] {KEY_ROWID,
KEY_ROUTERIP, KEY_PROJECTNAME, KEY_URL, KEY_CALIMERO},
null, null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
What do I have to change to see the ListView in descending order? Or do I have to change something at my SimpleCursorAdapter?
Thanks!
When running the query, the 2nd to last parameter (null at the moment) is the Order By
parameter: https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#query%28boolean,%20java.lang.String,%20java.lang.String%5B%5D,%20java.lang.String,%20java.lang.String%5B%5D,%20java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String%29
You'd need to pick the column by which you want to sort, and change that. To be safe, you should probably explicitly sort in both "normal" and "reverse" order, to be sure that it is ordering by the same column.