显示名称和s_no

时间:2012-10-13 07:04:07

标签: android listview

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();

1 个答案:

答案 0 :(得分: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的简单方法:

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();