I have a problem with my query
public ArrayList<String> getUniqueYears(String TABLE_NAME) {
ArrayList<String> content = new ArrayList<String>();
final String[] cat = new String[] {KEY_YEAR};
Cursor cursor = myDatabase.query(true, TABLE_NAME, cat, null, null, null, null, KEY_YEAR, null);
if (cursor.moveToFirst()) {
do {
content.add(cursor.getString(0));
} while(cursor.moveToNext());
}
cursor.close();
return content;
}
when i call the function returns me this:
[111, 1111, 124, 1242, 1345, 1943, 2345, 345]
thank’s
It is currently sorting by
KEY_YEARas if those where strings:111and1111 are equal, but the second one has an extra character, thus i is “numerically greater” than the first one.1111 and124 are equal, but 1111 is “numerically lower” than 124. The rest is not used for sorting this pairAnd so and so….
How are you storing
KEY_YEAR? It should be aNUMBER