在查询数据库时,您仍然会有一个光标,但是一旦获得光标,您可以迭代它,将所需的值拉出到数组中,如下所示:
DbAdapter db = new DbAdapter(mContext);
int columnIndex = 3; // Whichever column your float is in.
db.open();
Cursor cursor = db.getAllMyFloats();
float[] myFloats = new float[cursor.getCount()-1];
if (cursor.moveToFirst())
{
for (int i = 0; i < cursor.getCount(); i++)
{
myFloats[i] = cursor.getFloat(columnIndex);
cursor.moveToNext();
}
}
cursor.close();
db.close();
// Do what you want with myFloats[].
这篇博客介绍了如何在Android环境中使用数据库查询并迭代光标,将特定列的浮点数值存储到数组中。通过示例代码展示了从数据库获取数据,遍历Cursor并利用Float类型的数组进行存储,最后关闭资源的过程。
1811

被折叠的 条评论
为什么被折叠?



