我希望通過名爲score的變量對我的listView進行排序。任何人都知道如何做到這一點?目前這裏是我的代碼,它從數據庫中獲取信息並將其顯示在列表視圖中。Sorting Listview Java
List<String> queryTable(){
List<String> player = new ArrayList<String>();
SQLiteDatabase db = myOpenHelper.getReadableDatabase();
Cursor cursor = db.query(CustomOpenHelper.TABLE_NAME, null, null, null, null, null, null);
while (cursor.moveToNext()) {
int id = cursor.getInt(cursor.getColumnIndex("_id"));
String name = cursor.getString(cursor.getColumnIndex("name"));
int score = cursor.getInt(cursor.getColumnIndex("score"));
player.add(id + " --> the player " + name + " has got a score of " + score +"s");
}
那麼我該如何去排序這個listview的變量「分數」?多謝你們。
嘗試使用可比 – 2014-09-29 06:38:13
從數據庫中獲得的信息已經被排序。這個'ORDERY BY columnname'有sql關鍵字您可以添加'ASC'或'DESC'來升序或降序 – user28470 2014-09-29 06:40:23