0
Cursor cur = acc.query("details", new String[] { "name"}, null,
            null, null, null, null);

    cur.moveToFirst();
    listContent = new String[cur.getCount()];
    for (i = 0; i < cur.getCount(); i++) {
        String ss1;
        ss1 = cur.getString(0);
        listContent[i] = ss1;

        cur.moveToNext();
    }
    cur.close();
4

1 回答 1

0

尝试:

Cursor cur = acc.query("details", new String[] { "name"}, null,
        null, null, null, null);
listContent = new String[cur.getCount()];
int i=0;
while(cur.moveToNext()) {
    listContent[i] =cur.getString(0);
     i++;
}
cur.close();

并且不使用任何索引计数器的简单方法使用 ArrayList 而不是 Array as:

Cursor cur = acc.query("details", new String[] { "name"}, null,
        null, null, null, null);
 List<String> strArrayList = new ArrayList<String>();

while(cur.moveToNext()) {
    strArrayList.add(cur.getString(0));
}
cur.close();
于 2012-10-13T07:11:36.647 回答