我想从我的数据库中获取所有行的第一列中的数据并转换为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 );
我试图逐步评论,发现问题出在循环中.... 请帮助......提前感谢所有答案。
答案 0 :(得分: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[] {};
}
}
答案 1 :(得分:-1)
我明白了:
c.moveToFirst();
do
{
item1.add(c.getString(0).toString());
//i++;
}while(c.moveToNext());