我有一個名爲users(_id,name)的表的數據庫。 我使用下面的方法來獲得名Android;如何通過光標填充ListView
public Cursor getAllNames() {
return db.query(DATABASE_TABLE, new String[] { KEY_ROWID, KEY_NAME },
null, null, null, KEY_NAME+" ASC", null);
}
現在我檢索光標在列表活動的升序排列的所有記錄如下
DBAdapter db= new DBAdapter(this);
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.lview);
ListView l=(ListView) findViewById(R.id.listView1);
db.open();
Cursor c=db.getAllNames();
db.close();
}
我試圖用簡單的光標適配器遍歷名稱並將其分配給列表視圖。但既然已經貶值了怎麼實現呢?
https://github.com/lalit3686/CursorAdapter –
@LalitPoptani是它的一個示例代碼? –
是的,你可以下載並檢查它。 –