我尝试了以下代码,使用android
中的where子句返回多个列值public Cursor getData(String text) {
SQLiteDatabase db = this.getWritableDatabase();
String[] columns = new String[]{"Client","Action","Value","Period"};
Cursor cr = db.query("phrase_table",columns,"phrase = ?",new String[]{text},null,null,null);
return cr;
}
但是,光标仅返回“Client”列值。这是光标到字符串的代码:
Cursor c = vdb.getData(text);
ArrayList<String> line= new ArrayList<>();
if (c.moveToFirst()) {
do{
line.add(c.getString(0));
}while(c.moveToNext());
}
String resc="";
for(String a:line){
resc += a;
}
Toast.makeText(this,resc,Toast.LENGTH_LONG).show();
也试过这个:
Cursor c = vdb.getData(text);
String line = "";
if (c.moveToFirst()) {
do{
line += c.getString(0);
}while(c.moveToNext());
}
Toast.makeText(this,resc,Toast.LENGTH_LONG).show();
但结果是一样的。
答案 0 :(得分:3)
您正从光标“客户端”获取单个数据,更新其他
的代码if (c.moveToFirst()) {
do{
line += c.getString(0);
line += c.getString(1);
line += c.getString(2);
line += c.getString(3);
}while(c.moveToNext());
}