-1

I am using a method with a cursor to return all values that has the same id, like for example:

ID_Owner | ID_Car

1 -------- 1

1 -------- 2

The owner with the id, has the car 1 and 2..


With my method im returning those values:

// Seleciona o Registo com o ID especeficado
public Cursor selectMotivosWhereId(long id){
    String sql = "SELECT * FROM Motivo_sintomas WHERE _ID IN (SELECT id_motivo FROM Sintoma_motivos WHERE id_sintoma = ?) " ;
    String[] args = new String[]{id + ""};
    Cursor result = this.db.rawQuery(sql, args);
    return result;
}

And then, i want to show them in the same textview, but only the last one is displayed, i think its because the .setText overwrites and only the last one is shown.

Cursor res2 = dal.selectMotivosWhereId(position);
    res2.moveToFirst();
    while (!res2.isAfterLast()) {
        Motivo.setText(res2.getString(res2.getColumnIndex(DBContract.Motivo_sintomas.COL_Motivo)));
        res2.moveToNext();
    }

How can i keep adding the values to the edittext and separate them with a "-" or "," ?

Thanks so much.

1 Answers1

0

You have to use the StringBuilder and append the result to StringBuilder object and then set text the stringbuilder object.

Cursor res2 = dal.selectMotivosWhereId(position);
res2.moveToFirst();
StringBuilder sb = new StringBuilder();
while (!res2.isAfterLast()) 
{
    sb.append(res2.getString(res2.getColumnIndex(DBContract.Motivo_sintomas.COL_Motivo));
    res2.moveToNext();
}
 Motivo.setText(sb.toString());
Prateek
  • 306
  • 4
  • 17
  • Thank you ! How can i add a comma or "-" between each value ? – Duarte Andrade Jun 12 '16 at 18:18
  • For Display you have to store the result in two different variables like ID_owner and ID_Car and then display in desired format. sb.append(ID_Owner+"------"+ID_CAR); – Prateek Jun 12 '16 at 18:24