I’m creating a SQLite database where it is possible to make entries for a specific day in the month. I’ve made a column for the day-number. The entries come in random order, so i wanna sort them. But when i use the orderBy it only sort the numbers by the first digit.
Example: the entry order is (2,31,5,21,16,9,7). When i then sort it i get the order (16,2,21,31,5,7,9). Is there a way to fix this?
My entry code
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();
}
And my code where i sort the data
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);"
);
}
It’s ordering alphabetically. Try: