【问题标题】:How to read out two columns from table and multiplize them?如何从表中读出两列并将它们相乘?
【发布时间】:2012-02-07 15:27:04
【问题描述】:

如何在 Android Java 中实现这一点? 所以我的意思是如何读出标记和重量,将它们相乘并使用相同的系统添加下一行?:

这就是我现在在 ListView 中列出这些标记的内容:

private void fillData() {

Bundle extras = getIntent().getExtras();
    String txt_sub_id = extras.getString("IDFach");
    int test = Integer.parseInt(txt_sub_id);

Cursor mCursor = db.rawQuery("SELECT _id, subid, name, mark, gewicht, datum FROM tbl_marks WHERE subid = '"+test+"';", null);
startManagingCursor(mCursor);
if (mCursor != null && mCursor.moveToFirst()) {
     int intName = mCursor.getColumnIndexOrThrow("subid");

      do {
          teststring = mCursor.getString(intName);

          String[] from = new String[] { dbHelper.KEY_NAME_MARKS, dbHelper.KEY_MARK_MARKS, dbHelper.KEY_GEWICHT_MARKS, dbHelper.KEY_DATUM_MARKS};
          int[] to = new int[] {R.id.txt_marks_row, R.id.txt_note, R.id.txt_gewicht, R.id.txt_datum};

          SimpleCursorAdapter notes = new SimpleCursorAdapter(this, R.layout.show_marks, mCursor, from, to);
          setListAdapter(notes);
      } while (mCursor.moveToNext());
}
    }

看起来像这样:

我喜欢拥有的东西:

提前致谢!

【问题讨论】:

  • 我必须知道如何从数据库中读取这些列并处理它们...... ;)

标签: android sqlite add


【解决方案1】:

您需要在 do/while 循环中执行以下操作。这里 4 是查询中列名的索引。

  int mark=mCursor.getInt(4);
   int wght=mCursor.getInt(5);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多