This is my code so far to retrive values from database to the listview. I need to make them appear according to alphabetical order. How should I change this code? Please help!
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;
}
You could use your query like this:
db.rawQuery("SELECT *
FROM " +tableName +" ORDER BY " +yourcolumnName+ " DESC", null);
hope it helps.
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加