【发布时间】:2010-10-27 00:14:27
【问题描述】:
我有一个列表,我用数据库中的数据填充,现在我想按标题和日期对这些数据进行排序。
我对 Android 编程还是新手,所以在这里无法弄清楚如何做到这一点,希望有人能提供帮助。
以下是列表的填写方式:
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();
}
这里是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);
}
【问题讨论】:
-
你提问的主题与问题本身无关?
-
该代码中没有 if 语句
-
这里发生了一些奇怪的事情......标题错误..改了..问题与“if”无关..问题在文中解释。
标签: sql android database list sorting