Array constants can only be used in initializers
public String[] getData(){
String[] columns = {KEY_ROWID, KEY_TIME, KEY_TXT};
Object[] data;
Cursor c = database.query(DB_TABLE, columns, null, null, null, null, null);
int iRow = c.getColumnIndex(KEY_ROWID);
int iTime = c.getColumnIndex(KEY_TIME);
int iTxt = c.getColumnIndex(KEY_TXT);
开发者_StackOverflow for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
data[c.getPosition()+1] = {c.getString(iRow), c.getString(iTime), c.getString(iTxt)};
}
return data;
}
You pretty much get the idea what I wanna do here. Can't update the data variable from for loop. But I would need to do that. How?
You just have to use slightly different syntax:
data[c.getPosition()+1] =
new String[]{c.getString(iRow), c.getString(iTime), c.getString(iTxt)};
精彩评论