troubleshooting Question

android java how to loop a database results

Avatar of derrida
derrida asked on
14 Comments2 Solutions432 ViewsLast Modified:
i'm new to java and android. i have a sqlite database, i have this code in my database class, to get all records:
    public Cursor getAllQuotes(){
        SQLiteDatabase db = this.getWritableDatabase();
        Cursor res = db.rawQuery("SELECT * FROM quotes a LEFT JOIN authors b ON b.author_id=a.quote_author", null);
        return res;

then in my main activity i have a list i need to populate with the results:
    private ArrayList<DataObject> getTheData(){
        ArrayList res = new ArrayList<DataObject>();
        Cursor dbresults = Qdb.getAllQuotes();


now i don't understand how to loop the dbresults and send author name and quote to the dataobject. i need to pass the author name and quote so seem to me i need something like:
DataObject obj = new DataObject("author name","the quote");
but that should be within a loop and somehow can't figure out how exactly to do it.

best regards
Join our community to see this answer!
Unlock 2 Answers and 14 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 14 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros