0

我想从我的数据库中获取所有行的第一列中的数据并转换为 String[] ...

List<String> item1 = new ArrayList<String>();
// c is a cursor which pointed from a database
for(int i=0;i<=nombre_row;i++)
    {
        c.moveToPosition(i);
        item1.add(c.getString(0));
    }
String[] strarray = new String[item1.size()];
item1.toArray(strarray );

我试图一步一步地发表评论,发现问题出在循环中......请帮助......提前感谢所有回答。

4

2 回答 2

0
public String[] getData()
{
    Cursor cursor = this.db.query(/your query/);

    if(cursor.getCount() >0)
    {
        String[] str = new String[cursor.getCount()];
        int i = 0;

        while (cursor.moveToNext())
        {
             str[i] = cursor.getString(cursor.getColumnIndex(Columname));
             i++;
         }
        return str;
    }
    else
    {
        return new String[] {};
    }
}
于 2012-10-13T15:43:28.493 回答
-1

我得到了它的工作:

c.moveToFirst();
                do
                {
                    item1.add(c.getString(0).toString());
                    //i++;
                }while(c.moveToNext());
于 2012-10-13T16:05:31.443 回答