I have a list that i fill with data from a database, and now i want to sort this data by title and date.
Im still new to programming for Android, so cant figure out how to do this here, hope someone can help.
Here is how the list is filled:
public void fillData()
{
// get all the data from database
DBAdapter db = new DBAdapter(this);
db.open();
mCategoriesCursor = db.getAllTitles();
startManagingCursor(mCategoriesCursor);
String[] from = new String[] { DBAdapter.KEY_TITLE, DBAdapter.KEY_DATE };
int[] to = new int[] { R.id.text1, R.id.text2 };
// Now create an array adapter and set it to display using our row
SimpleCursorAdapter categories =
new SimpleCursorAdapter(this, R.layout.categories_row, mCategoriesCursor, from, to);
setListAdapter(categories);
db.close();
}
Here is the sql:
//---retrieves all the categories---
public Cursor getAllTitles()
{
return db.query(DATABASE_TABLE, new String[] {
KEY_ROWID,
KEY_TITLE,
KEY_DATE,
KEY_EXTRA},
null,
null,
null,
null,
null);
}