1

I need to display list of 10 best scores. I used this code to get the data and put it in a arraylist

private ArrayList<String> getData() {
    String[] columns = {DbHelper.COL_NAME, DbHelper.COL_SCORE};
    Cursor c = db.query(DbHelper.TABLE_NAME, columns, null, null, null, null, DbHelper.COL_SCORE, "10");
    int nameCol = c.getColumnIndex(DbHelper.COL_NAME);
    int scoreCol = c.getColumnIndex(DbHelper.COL_SCORE);
    for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
        scoresList.add(c.getString(nameCol) + " " + c.getString(scoreCol));
    }

    return scoresList;
}

The only problem that its ordered from the lowest score to the highest, and i need it reversed.

1
  • Add an ORDER BY Score DESC clause (by default, the ORDER BY statement operates as if you specified ASC) Commented Jun 10, 2017 at 13:27

1 Answer 1

1

Try with below query...

Cursor c = db.query(DbHelper.TABLE_NAME, columns, null, null, null, null, DbHelper.COL_SCORE +" DESC", "10");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.