📜  将 SQLite 返回的数据保存到对象列表 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:17.449000             🧑  作者: Mango

代码示例1
public void fillDataToArray() {

            ArrayList arrayList = new ArrayList();
            DatabaseHandler db = new DatabaseHandler(getActivity());
            db.open();
            try
        {
            Cursor c = db.getImageNameForList();

                if (c != null && c.getCount() > 0) {
                c.moveToFirst();
                for (int count = 0; count < c.getCount(); count++) {
                     Beanclass detail = new Beanclass ();

                     detail.setName(c.getString(c
                     .getColumnIndex(DatabaseHandler._ID)));

                     detail.setPath(c.getString(c
                     .getColumnIndexOrThrow(DatabaseHandler._PATH)));

                     arrayList.add(detail);
                    c.moveToNext();

                    }
                }
        }
    catch(Exception e)
        {
        e.printStackTrace();
        }
            c.close();
            db.close();

        }