-1
我打開我的數據庫使用手動方法,然後在第一次,我可以顯示列表上的數據,現在,當我改變表,它doens't工作,我可以'找不到錯誤:這是我的數據庫中的表:SQLITE - Android /顯示數據bug
主代碼顯示使用getalllines從DBhelper:
obj = (ListView) findViewById(R.id.listView1);
List<line> array_list = db.getAlllines();
ArrayAdapter<line> arrayAdapter = new ArrayAdapter<line>(this, android.R.layout.simple_list_item_1, array_list);
obj.setAdapter(arrayAdapter);
我的方法getalllines:
public List<line> getAlllines() {
List<line> lines = new LinkedList<line>();
String query = "SELECT * FROM " + TABLE_LINE;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(query, null);
// 3. go over each row, build book and add it to list
line linee = null;
if (cursor.moveToFirst()) {
do {
linee = new line();
linee.setId(Integer.parseInt(cursor.getString(0)));
linee.setLinename(cursor.getString(1));
linee.setFromgare(cursor.getString(2));
linee.setTogare(cursor.getString(3));
lines.add(linee);
} while (cursor.moveToNext());
}
Log.d("getAlllines()", lines.toString());
return lines;
}
,如果你需要知道如何創建表:
@Override
public void onCreate(SQLiteDatabase db) {
// SQL statement to create book table
String CREATE_LINES_TABLE = "CREATE TABLE lines (" +
"_id INTEGER NOT NULL," +
"linename VARCHAR," +
"fromgare VARCHAR," +
"togare VARCHAR," +
"PRIMARY KEY(_id))";
// create books table
db.execSQL(CREATE_LINES_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop older books table if existed
db.execSQL("DROP TABLE IF EXISTS lines");
// create fresh books table
this.onCreate(db);
}
是什麼意思odesn't工作? – e4c5
我有一個包含10行的完整表格,但它什麼都沒顯示 –
嘗試從onResume方法中的數據庫中檢索數據(如果您打開另一個活動以在數據庫中進行更改)。 –