我正在创建一个 SQLite 数据库,可以在其中为一个月中的特定日期创建条目。我为天数做了一个专栏。这些条目是随机顺序的,所以我想对它们进行排序。但是当我使用 orderBy 时,它只按第一个数字对数字进行排序。示例:挂单是 (2,31,5,21,16,9,7)。然后,当我对其进行排序时,我得到了顺序(16、2、21、31、5、7、9)。有没有办法解决这个问题?
我的进入码
public void createEntry(int id, int month, int day, int start_hour, int start_min, int stop_hour, int stop_min)
{
ContentValues cv = new ContentValues();
ourDatabase.beginTransaction();
cv.put(ROW_ID, id);
cv.put(MONTH,month);
cv.put(DAY,day);
cv.put(START_HOUR,start_hour);
cv.put(START_MIN,start_min);
cv.put(STOP_HOUR,stop_hour);
cv.put(STOP_MIN,stop_min);
ourDatabase.insert(DATABASE_TABLE, null, cv);
ourDatabase.setTransactionSuccessful();
ourDatabase.endTransaction();
}
还有我对数据进行排序的代码
public ArrayList<String> getDays(){
String[] columns = new String[]{MONTH, DAY, START_HOUR, START_MIN, STOP_HOUR, STOP_MIN};
Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, DAY);
c.moveToLast();
ArrayList<String> navne = new ArrayList<String>();
for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
Log.d("Entry", c.getString(1));
navne.add(c.getString(1)+": "+c.getString(2)+":"+c.getString(3)+" - "+c.getString(4)+":"+c.getString(5));
}
return navne;
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" +
ROW_ID + " TEXT NOT NULL, " +
MONTH + " TEXT NOT NULL, " +
DAY + " TEXT NOT NULL, " +
START_HOUR + " TEXT NOT NULL, " +
START_MIN+ " TEXT NOT NULL, " +
STOP_HOUR + " TEXT NOT NULL, " +
STOP_MIN + " TEXT NOT NULL);"
);
}