lundi 21 mars 2016

Sorting sqlite table showing in my listview not working in Android

I am using the following to sort a table of players based on their position

public ArrayList<Player> getAllPlayers()
{
    ArrayList<Player> players = new ArrayList<Player>();
    String selectQuery = "SELECT  * FROM " + TABLE_PLAYERS + " ORDER BY "+"p_position"+" ASC";

    // Log.e(LOG, selectQuery);

    SQLiteDatabase db = this.getReadableDatabase();
    Cursor c = db.rawQuery(selectQuery, null);

    // looping through all rows and adding to list
    if (c.moveToFirst()) {
        do {
            Player td = new Player();
            td.setPlayerId((c.getInt(c.getColumnIndex(TABLE_PLAYERS_ID))));
            td.setPlayerName((c.getString(c.getColumnIndex(TABLE_PLAYERS_NAME))));
            td.setPlayerPosition(c.getString(c.getColumnIndex(TABLE_PLAYERS_POSITION)));
            td.setPlayerNumber(c.getString(c.getColumnIndex(TABLE_PLAYERS_NO)));


            // adding to todo list
            players.add(td);
        } while (c.moveToNext());
    }

    return players;
}

I am trying to sort my table which is displayed in a listview but sorting has no effect why is that?

Aucun commentaire:

Enregistrer un commentaire