-1
我發現一些教程,創建databaseHelper類,它幫我來從數據庫中的數據填充的GridView和ListView,數據被讀取使用名單,但不知何故,我不知道如何來填充列表到ArrayList中我的GridView和列表視圖,當我嘗試,它說列表無法轉換成ArrayList中。我怎樣才能做到這一點?我在這裏的代碼片斷從databaseHelper創建的列表
databaseHelper.java
public List<Seat> getAllSeats() {
List<Seat> seats = new ArrayList<Seat>();
String selectQuery = "SELECT * FROM " + TABLE_SEATS + "WHERE status=0";
Log.e(LOG, selectQuery);
SQLiteDatabase db = this.getReadableDatabase();
Cursor c = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (c.moveToFirst()) {
do {
Seat seat = new Seat();
seat.set_id(c.getInt((c.getColumnIndex("id"))));
seat.set_table_no(c.getString(c.getColumnIndex("table_no")));
// adding to list
seats.add(seat);
} while (c.moveToNext());
}
return seats;
}
index.java
/* LIST SEAT */
final ArrayList<Seat> list_seat = db.getAllSeats();
final GridView gridview_seat = (GridView) findViewById(R.id.gridviewSeat);
gridview_seat.setAdapter(new SeatListAdapter(this, list_seat));
爲第三行:arrayList.addAll(名單);,不應該是list_seat呢?我更新到list_seat及其作品!謝謝! – Gabriel
是的,你是對的。 –