我正在尝试将iScore和显示相加并可能存储但不确定如何。
public String getData() {
String[] columns = new String[] { KEY_ROWID, KEY_SCORE, KEY_PUTTS };
Cursor c = csDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);
String result = "";
int iRow = c.getColumnIndex(KEY_ROWID);
int iScore = c.getColumnIndex(KEY_SCORE);
int iPutts = c.getColumnIndex(KEY_PUTTS);
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
result = result + c.getString(iRow) + " " + c.getString(iScore) + " " +
c.getString(iPutts) + "\n";
}
return result;
}
答案 0 :(得分:0)
我不确定你想做什么,但是: 如果你想在KEY_SCORE中对数字求和,那么
result = result + c.getString(iScore);
或
result = result + c.getString(1);
OR:
public static final String KEY_ROWID = "_id";
public static final String KEY_SCORE = "pscore";
public static final String KEY_PUTTS = "pputts";
然后在getData方法中:
Cursor c = ourDatabase.query(DATABASE_TABLE, new String[] { "_id","sum(pscore)","pputts" },
null,null,null , null, null);
答案 1 :(得分:0)
你正在试图'总结'字符串。 +
是连接运算符。将它们转换为数字,然后将它们一起添加。