0

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 given 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();
    }
}

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

i don't quite understand.. could you send me a modified version of the code
It would be better for you to look at some ListView examples and then try to populate what I have answered. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.