喜使用SQLite我,我需要顯示所有coulms的名字,但列表視圖只顯示最後colums命名支票影像enter image description here One is last addedsqlite的列表視圖只顯示最後科拉姆或一個
private void ListShow() { list = findViewById(R.id.list); myDb.getReadableDatabase(); myDb.getWritableDatabase(); Cursor res = myDb.getAllData(); while (res.moveToNext()) { String[] strNAME = new String[]{res.getString(0) }; ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, strNAME); list.setAdapter(adapter); adapter.notifyDataSetChanged(); } }
public Cursor getAllData() {
SQLiteDatabase db = this.getWritableDatabase();
Cursor res = db.rawQuery("select * from "+TABLE_NAME,null);
return res;
}
因爲您正在重新創建並在每次循環迭代時重新分配ArrayAdaper。另外請注意,你濫用'notifyDatabaseChanged()'方法 –