到目前为止,这是我的代码,用于将值从数据库检索到列表视图。我需要使它们按照字母顺序出现。我应该如何更改此代码?请帮忙!
public List<Units> getAllUnit() {
List<Units> unit = new ArrayList<Units>();
SQLiteDatabase db = getWritableDatabase();
Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_UNITS, null);
if (cursor.moveToFirst()) {
do {
unit.add(new Units(Integer.parseInt(cursor.getString(0)) , cursor.getString(1), cursor.getString(2), cursor.getString(3)));
}
while (cursor.moveToNext());
}
cursor.close();
db.close();
return unit;
}
您可以像这样使用查询:
db.rawQuery("SELECT *
FROM " +tableName +" ORDER BY " +yourcolumnName+ " DESC", null);
希望能帮助到你。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句