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;
}
解决方案
请将 sqlquery 更改为此
String sql = "Select * From " + TABLE_NAME+"ORDER BY DATE_COLUMN_NAME desc";
推荐阅读
- visual-studio-code - 如何在 Visual Studio Code 的“文件”菜单中添加新菜单项?
- c++ - 如何在跨平台的 C++ 中以毫秒为单位获取系统启动/启动时间(它应该在 windows / IOS / Android / MAC 中工作)
- c# - Foreach-Object 项到数组,而不是子数组
- python - 如何修复“查询”对象没有属性“包含列引用”错误
- javascript - 无效的 API 令牌
- python - Django 设置文件中的 Django 错误 - 类型错误:预期的 str、字节或 os.PathLike 对象,而不是元组
- ansible - 如何在ansible中一起使用loop和with_nested
- php - Laravel Scout TNTSearch - 500 个结果的限制
- javascript - 评估前缀表达式的值 - JS
- python - 为什么可以调用超类没有的方法