首页 > 解决方案 > 日期降序排列

问题描述

我想按降序排列日期和时间。这是我使用这种方法所做的。所以,你能弄清楚如何按顺序排列它们吗?

我的代码:

public ArrayList<Modules> getAllData()
{
    ArrayList<Modules> list = new ArrayList<>();
    String sql = "Select * From " + TABLE_NAME;
    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cursor = db.rawQuery(sql, null);
    if(cursor.moveToLast())
    {
        do{

            Modules m = new Modules();
            m.setID(cursor.getInt(0) + "");
            m.setName(cursor.getString(1));
            m.setDescription1(cursor.getString(2));
            m.setDescription2(cursor.getString(3));
            m.setDescription3(cursor.getString(4));
            m.setDescription4(cursor.getString(5));
            m.setDescription5(cursor.getString(6));
            m.setCurrentDate(cursor.getString(7));
            m.setCurrentTime(cursor.getString(8));
            list.add(m);

        }while (cursor.moveToNext());

    }
    return list;

}

标签: android

解决方案


请将 sqlquery 更改为此

 String sql = "Select * From " + TABLE_NAME+"ORDER BY DATE_COLUMN_NAME desc";

推荐阅读