vendredi 3 avril 2015

How to get values from database to set valies ina list view according to alpherbatical order

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;
}

Aucun commentaire:

Enregistrer un commentaire