本帖最後由 ploglin 於 2011-12-5 09:24 編輯
作法有很多種,我自己的用法如下
- ArrayList<HashMap<String, Object>> tmplist_db = new ArrayList<HashMap<String, Object>>();
- DownloadHelper dbhelper = new DownloadHelper(this);
- Cursor cursor = dbhelper.getReadableDatabase().rawQuery("select id, type, title, image, intro from news where type=?",
- new String[]{type});
- cursor.moveToFirst();
- for (int i = 0; i < cursor.getCount(); i++) {
- HashMap<String, Object> map = new HashMap<String, Object>();
- map.put("id", cursor.getString(0));
- map.put("type", cursor.getString(1));
- map.put("title", cursor.getString(2));
- map.put("image", cursor.getString(3));
- map.put("intro", cursor.getString(4));
- tmplist_db.add(map);
- cursor.moveToNext();
- }
- cursor.close();
- dbhelper.close();
複製代碼 |