I have a Database with a table called users(_id,name).
I am using the following method to get all the records in the ascending order of names
public Cursor getAllNames() {
return db.query(DATABASE_TABLE, new String[] { KEY_ROWID, KEY_NAME },
null, null, null, KEY_NAME+" ASC", null);
}
Now i am retrieving the Cursor in the List Activity as follows
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();
}
I am trying to use Simple Cursor Adapter to iterate thru the names and assign it to the List View. But since it has be depreciated how to achieve the same ?
You can create a custom Adapter that extends BaseAdapter and holds an ArrayList of items.
After you call the getAllNames() and you have all your items in the Cursor, iterate over the Cursor and put all those items in the ArrayList from the CustomAdapter. Then just set the CustomAdapter as the ListView adapter.