Android - load values from sqlite database to an arraylist

后端 未结 3 1167
盖世英雄少女心
盖世英雄少女心 2021-02-04 17:34

I am new to android . I have an application working with SQLite DB. I need to push values from database to an arraylist of type object. The code i used is given here.



        
3条回答
  •  暖寄归人
    2021-02-04 18:19

    I had a similar issue with retrieving values from the db using cursors and displaying on screen.. The below solution works for me..

                Cursor cur = db.getAllValues();
                int index = c.getColumnIndex("date");
        cur.moveToFirst();
    
        while (cur.isAfterLast() == false) {
            System.out.println(cur.getString(index)); // For debug purposes
            String date = cur.getString(index);
            try {
                ob = new objectname();
                ob.setDate(date);
                resultList.add(ob);
            } catch (Exception e) {
                Log.e(MY_DEBUG_TAG, "Error " + e.toString());
            }
            cur.moveToNext();
        }
        cur.close();
    

提交回复
热议问题