• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Printing SQL enteries in a listview

hayes121

Lurker
Nov 2, 2014
1
0
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
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones