Apps Printing SQL enteries in a listview

hayes121

Lurker
I am having some trouble learning the ins and outs of the SQLite world. I have some code that is allowing me to enter data into a DB. But what i want to do is return this data into a listview. At the moment all I could figure out to do was to have each row printed in a toast after a new entry is added. Can someone please show me how to alter my code to print it in a listview? Or to even look at my code and see that i am going about it in the right way. Thanks


This is the code i am using which calls a display record function

Code:
        //---get all Records---
        com.example.rory.dbtest.DBAdapter db = new com.example.rory.dbtest.DBAdapter(this);
        db.open();
        Cursor c = db.getAllRecords();
        if (c.moveToFirst())
        {
            do {
                DisplayRecord(c);
            } while (c.moveToNext());
        }
        db.close();


This is the display record function
Code:
    public void DisplayRecord(Cursor c)
    {
       Toast.makeText(this,
                "id: " + c.getString(0) + "\n" +
                        "Item: " + c.getString(1) + "\n" +
                        "Litres:  " + c.getString(2),
                Toast.LENGTH_SHORT).show();
    }
I know i need to change the second function but i dont know how to do that to make it print into a listview
 
Top