Search code examples
javaandroidsimplecursoradapter

Display data from CursorAdapter in ascending order of Id in a ListView?


I am retrieving data from my sqlite database table (which has Id and text) as Cursor and setting it to ListView using SimpleCursorAdapter as below:

Cursor cursor = rawQuery("select IdColumn, TextColumn from Comments  where whereArgs ",
            new String[]{whereArgs});
 adapter = new android.support.v4.widget.SimpleCursorAdapter(context,
            android.R.layout.two_line_list_item,
            cursor,
            new String[]{"IdColumn", "TextColumn"},
            new int[]{android.R.id.text1, android.R.id.text2},
            0);
listView.setAdapter(adapter);
}

The output is displayed as follows:

enter image description here

I want the data to displayed in ascending order of Id like this;

1

2

3

4

5

6

.....so on.

Please help!

Edit: I am newbie to programming.


Solution

  • Add in your SQL query a ORDER BY ID ASC.

    Related: Need to show a SQLite query in descending order