Database add item to list view?
I download this database script and i was wondering how can i convert it to instead add a item to a list view.. its a really easy understandable database code..
http://www.anotherandroidblog.com/wp-content/uploads/2010/08/AABDatabase.zip
Thats the source for it..
also im guessing it could be in here??
/**
* retrieves a row from the database with the id number in the corresponding
* user entry field
*/
private void retrieveRow()
{
try
{
// The ArrayList that holds the row data
ArrayList<Object> row;
// ask the database manager to retrieve the row with the giv开发者_运维技巧en rowID
row = db.getRowAsArray(Long.parseLong(updateIDField.getText().toString()));
// update the form fields to hold the retrieved data
updateTextFieldOne.setText((String)row.get(1));
updateTextFieldTwo.setText((String)row.get(2));
}
catch (Exception e)
{
Log.e("Retrieve Error", e.toString());
e.printStackTrace();
}
}
To add the items from database to a ListView you can have an ArrayList
1.) ArrayList<String> arrList = new ArrayList<String>();
2.) Fetch items from database and add them to ArrayList
if(c.getCount() > 0){
c.moveToFirst();
for (int i = 0; i < c.getCount() - 1; i++) {
arrList.add(c.getString(0));
c.moveToNext();
}
3.) Then populate the Adapter with the ArrayList(arrList).
4.) And fill the ListView with the Adapter.
精彩评论