I'm trying to get from a SELECT, the values from 2 columns in my SQLite Database, and when I retrieve it, I want to add this values in a custom ArrayList that I created that have (String, String) parameters.
My DB Helper method is:
public ArrayList<Custom> getAllvalues(String TABLE, String COLUMN1, String COLUMN2) {
ArrayList<Custom> list = new ArrayList<Custom>();
// Select All Query
String selectQuery = "SELECT "+COLUMN1+","+COLUMN2+" FROM " + TABLE;
SQLiteDatabase db = this.getWritableDatabase();
try {
Cursor cursor = db.rawQuery(selectQuery, null);
try {
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
list.add(new Custom(cursor.getString(0),cursor.getString(1)));
} while (cursor.moveToNext());
}
} finally {
try { cursor.close(); } catch (Exception ignore) {}
}
} finally {
try { db.close(); } catch (Exception ignore) {}
}
return list;
}
When I get the values, in my main class.. I get like this:
VALUE1 NULL;
NULL VALUE2;
VALUE3 NULL;
NULL VALUE4;
and I want that the values be in the list like this:
VALUE1 VALUE2;
VALUE3 VALUE4;
I tried to acces to the cursor like this:
cursor.getColumnIndex("My_column_name");
And I retrieved the values, but always in the same order.. value,null,null,value,value,null,etc...
Thank you!