例如,我有这张表:
我正在使用以下方法从该表中查询:
public ArrayList<ArrayList<String>> getAllViandCategory() {
ArrayList<ArrayList<String>> data2 = new ArrayList<ArrayList<String>>();
ArrayList<String> data = new ArrayList<String>();
// Select All Query
String selectQuery = "SELECT * FROM " + "tbl_viand_category";
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do {
data.add(cursor.getString(0));
data.add(cursor.getString(1));
data2.add(data);
} while (cursor.moveToNext());
}
return data2;
}
我没有得到想要的输出。我得到这个:[1,Fish,2,Vegetables,3,Meat,4,Rice,5,Etc]
而不是[[1,Fish],[2,Vegetables],[3,Meat],[4,Rice],[5,Etc]]