【发布时间】:2012-03-14 02:53:49
【问题描述】:
我一直在寻找/对以下代码进行不同的处理:
public String[] getData() {
String[] columns = new String[]{ app_name, app_location, app_dateTime};
Cursor c = myDatabase.query(app_table, columns, null, null, null, null, null);
int iName = c.getColumnIndex(app_name);
int iLoc = c.getColumnIndex(app_location);
int iDate = c.getColumnIndex(app_dateTime);
String[] appointments = new String[c.getColumnCount()];
int j = 0;
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
appointments[j] = " Appointment Name: " + c.getString(iName) + " \n Location: " + c.getString(iLoc) + " \n Date: " + c.getString(iDate) + " \n\n ";
j++;
}
return appointments;
}
}
基本上,这段代码的目的是将我的查询结果输入一个数组,然后通过代码的“返回约会”部分在另一个类的 ListView 中访问。出于某种原因,我的代码似乎无法正常工作,我无法完全确定它,我尝试了循环中的循环我尝试过使代码变暗,然后扩展我可以开始工作的内容,但没有一个给出给我一个解决方案。
【问题讨论】:
标签: android arrays sqlite loops cursor