我有一个名为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是它的一个示例代码? –
是的,你可以下载并检查它。 –