Android sqlite查询与编辑文本整数相乘?

时间:2011-10-14 05:19:55

标签: android sqlite

protected void cal() {
    // TODO Auto-generated method stub
    Company obj1 = new Company();
    String val1 = obj1.getCompanyID();
    edite.getText().toString();

    Cursor sumw = dbObject.rawQuery(
            "SELECT sum(Volume)FROM SHARE WHERE _id2 LIKE ?",
            new String[] { "%" + val1 + "%" });
    sumw.moveToFirst();
    editT.setText(sumw.getString(0));
}

我想获取EditText值的值,乘以查询的选定总和值

2 个答案:

答案 0 :(得分:2)

试试这个,

protected void cal() {
    // TODO Auto-generated method stub
    Company obj1 = new Company();
    String val1 = obj1.getCompanyID();
    int n = Integer.parseInt(edite.getText().toString());

    Cursor sumw = dbObject.rawQuery(
            "SELECT sum(Volume)FROM SHARE WHERE _id2 LIKE ?",
            new String[] { "%" + val1 + "%" });
    sumw.moveToFirst();
    editT.setText(sumw.getString(0)*n);
}

答案 1 :(得分:0)

如果它们是整数值,请尝试:

int multiplierOne = Integer.parseInt(edite.getText().toString());
....
int multiplierTwo = sumw.getInt(0);
int product = multiplierOne * multiplierTwo;
editT.setText("" + product);