My title may seem a bit improper, but I really don't know how to formulate this question.
Basically I got an Database with three columns which holds Text fields.
I would like to extract all values from a single column and group them in a huge string while separating them with \n.
The final three strings should be stored in a single String array. So I decided to query the DB with the three column names and loop through the entire table:
String[] columns = new String[] {KEY_DESCRIPTION, KEY_REPS, KEY_WEIGHT};
Cursor c = sqlDB.query(DATABASE_TABLE, columns, null, null, null, null, null);
String result[] = new String[3];
int iDesc = c.getColumnIndex(KEY_DESCRIPTION);
int iReps = c.getColumnIndex(KEY_REPS);
int iWeight = c.getColumnIndex(KEY_WEIGHT);
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) //loop thru
{
result[0] = result[0] + c.getString(iDesc) + "\n";
result[1] = result[1] + c.getString(iReps) + "\n";
result[2] = result[2] + c.getString(iWeight) + "\n";
}
return result;
I previously used a similar approach to concatenate all three strings, but now I need to have some sort of separation between those three values.
After retrieving the values I would like to insert them separately into Android TextViews:
TextView1.setText(string[0]);
TextView2.setText(string[1]);
TextView3.setText(string[2]);
So my actual question is should I keep on using this or should I choose an other way, such as one array list per string, etc. ?