如何从 Android SQLite 中获取值并将其存储到数组中?

How do I fetch the values from the Android SQLite and store into array?

我想为折线图制作图表。所以我参考了 achartEngine ,这是我的代码:

int[] x = {1, 2, 3, 4, 5};
int[] y = {24, 33, 15, 20, 55};
TimeSeries serial = new TimeSeries("Line 1");
for (int i = 0 ; i < x.length ; i++) {
     serial.add(x[i], y[i]);
}

XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
dataset.addSeries(serial);

到目前为止没有问题,但我不知道如何用 int 替换数组。

例如,我像这样使用 sqlite :

SQLiteDatabase db = dbhelper.getReadableDatabase();
String[] columns = {KEY_ID, TEMPER};  
Cursor cursor = db.query(TABLE_NAME, null, null);
int id = cursor.getColumnIndex(KEY_ID);
int ect = cursor.getColumnIndex(TEMPER);

我就是这种情况,有什么建议吗?

您不需要数组。无论您在哪里使用它,都将其替换为从光标读取的值:

int id = cursor.getColumnIndexOrThrow(KEY_ID);
int ect = cursor.getColumnIndexOrThrow(TEMPER);
while (cursor.moveToNext()) {
    serial.add(cursor.getInt(id), cursor.getInt(ect));
}