How do i order my SQLITE database in descending order, for an android app?

后端 未结 11 1705
死守一世寂寞
死守一世寂寞 2020-11-27 16:44

What is the most efficient method of showing my data in descending order?

public String getRank() {

    String[] rank = new String[]{ KEY_ROWID };
    Curso         


        
11条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 17:19

    public List getExpensesList(){
        SQLiteDatabase db = this.getWritableDatabase();
    
        List expenses_list = new ArrayList();
        String selectQuery = "SELECT * FROM " + TABLE_NAME ;
    
        Cursor cursor = db.rawQuery(selectQuery, null);
        try{
            if (cursor.moveToLast()) {
    
                do{
                    String info = cursor.getString(cursor.getColumnIndex(KEY_DESCRIPTION));
                    expenses_list.add(info);
                }while (cursor.moveToPrevious());
            }
        }finally{
            cursor.close();
        }
        return expenses_list;
    }
    

    This is my way of reading the record from database for list view in descending order. Move the cursor to last and move to previous record after each record is fetched. Hope this helps~

提交回复
热议问题