Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 停止.setText以防覆盖?从数据库游标结果_Java_Android_Android Database - Fatal编程技术网

Java 停止.setText以防覆盖?从数据库游标结果

Java 停止.setText以防覆盖?从数据库游标结果,java,android,android-database,Java,Android,Android Database,我使用带有游标的方法返回具有相同id的所有值,例如: 车主身份证 1--------1 1----2 有身份证的车主拥有1号和2号车 使用我的方法,我将返回这些值: // Seleciona o Registo com o ID especeficado public Cursor selectMotivosWhereId(long id){ String sql = "SELECT * FROM Motivo_sintomas WHERE _ID IN (SELECT id_moti

我使用带有游标的方法返回具有相同id的所有值,例如:

车主身份证

1--------1

1----2

有身份证的车主拥有1号和2号车


使用我的方法,我将返回这些值:

// 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;
}
然后,我想在同一个文本视图中显示它们,但只显示最后一个,我想这是因为.setText被覆盖,只显示最后一个

Cursor res2 = dal.selectMotivosWhereId(position);
    res2.moveToFirst();
    while (!res2.isAfterLast()) {
        Motivo.setText(res2.getString(res2.getColumnIndex(DBContract.Motivo_sintomas.COL_Motivo)));
        res2.moveToNext();
    }
我如何不断地将值添加到edittext中,并用“-”或“,”分隔它们


非常感谢。

您必须使用StringBuilder并将结果附加到StringBuilder对象,然后将文本设置为StringBuilder对象

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());

非常感谢。如何在每个值之间添加逗号或“-”呢?对于显示,您必须将结果存储在两个不同的变量中,如ID\u owner和ID\u Car,然后以所需的格式显示。某人附加(身份证持有人+“----”+身份证汽车);