views:

57

answers:

1

Hello. I have this code in my DataBase Helper:

public ArrayList<ArrayList<Object>> getAllRowsAsArrays()
{
    // create an ArrayList that will hold all of the data collected from
    // the database.
    ArrayList<ArrayList<Object>> dataArrays = new ArrayList<ArrayList<Object>>();

    // this is a database call that creates a "cursor" object.
    // the cursor object store the information collected from the
    // database and is used to iterate through the data.
    Cursor cursor;

    try
    {
        // ask the database object to create the cursor.
        cursor = db.query(
                TABLE_NAME,
                new String[]{TABLE_ROW_NAME},
                null, null, null, null, null
        );

        // move the cursor's pointer to position zero.
        cursor.moveToFirst();

        // if there is data after the current cursor position, add it
        // to the ArrayList.
        if (!cursor.isAfterLast())
        {
            do
            {
                ArrayList<Object> dataList = new ArrayList<Object>();

                dataList.add(cursor.getString(1));

                dataArrays.add(dataList);
            }
            // move the cursor's pointer up one position.
            while (cursor.moveToNext());
        }
    }
    catch (SQLException e)
    {
        Log.e("DB Error", e.toString());
        e.printStackTrace();
    }

    // return the ArrayList that holds the data collected from
    // the database.
    return dataArrays;
}

How do I use this code and show the results in a ListActivity?

Been stuck with this for the last 2 days. Any help on this is appreciated.

Thanks in advance.

A: 

You need to extend the SimpleCursorAdapter and have it return sub-views for rows. You can use the position of the row the ListView requests as an index into a row of your SQL results.

Watch this video on customizing ListView.

magaio