I have a list that I populate with data from a database, and now I want to sort this data by name and date.
I am still new to Android programming, so I can’t figure out how to do this, I hope someone can help.
Here's how to populate the list:
public void fillData()
{
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 };
SimpleCursorAdapter categories =
new SimpleCursorAdapter(this, R.layout.categories_row, mCategoriesCursor, from, to);
setListAdapter(categories);
db.close();
}
Here is sql:
public Cursor getAllTitles()
{
return db.query(DATABASE_TABLE, new String[] {
KEY_ROWID,
KEY_TITLE,
KEY_DATE,
KEY_EXTRA},
null,
null,
null,
null,
null);
}
source
share