日期按降序排列

时间:2019-02-21 05:43:50

标签: android

我想按降序排列日期和时间。这是我使用此方法所做的事情。因此,您能找出如何安排它们的顺序吗?

我的代码:

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;

}

1 个答案:

答案 0 :(得分:0)

请将sqlquery更改为此

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