綁定帳號登入

Android 台灣中文網

12
返回列表 發新帖
打印 上一主題 下一主題

[求助] ListView 顯示問題

[複製連結] 查看: 2580|回覆: 13|好評: 0
11
ploglin | 收聽TA | 只看該作者
發表於 2011-12-2 23:02
那你的 ArrayList 裡面有放資料嗎?
應該不會是空的吧?

  1. ArrayList<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
複製代碼
如果只有這一行程式,只是 new 一個空的 ArrayList 而已唷
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

12
 樓主| yuno5420 | 收聽TA | 只看該作者
發表於 2011-12-3 16:31
本帖最後由 yuno5420 於 2011-12-3 16:39 編輯

那要怎麼寫才能把我選擇的資料

按下儲存後(有放入資料庫)

從資料庫拿出來顯示在Listview的一欄


用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

13
ploglin | 收聽TA | 只看該作者
發表於 2011-12-5 09:23
本帖最後由 ploglin 於 2011-12-5 09:24 編輯

作法有很多種,我自己的用法如下

  1. ArrayList<HashMap<String, Object>> tmplist_db = new ArrayList<HashMap<String, Object>>();
  2. DownloadHelper dbhelper = new DownloadHelper(this);
  3. Cursor cursor = dbhelper.getReadableDatabase().rawQuery("select id, type, title, image, intro from news where type=?",
  4.                 new String[]{type});
  5. cursor.moveToFirst();
  6. for (int i = 0; i < cursor.getCount(); i++) {
  7.         HashMap<String, Object> map = new HashMap<String, Object>();
  8.         map.put("id", cursor.getString(0));
  9.         map.put("type", cursor.getString(1));
  10.         map.put("title", cursor.getString(2));
  11.         map.put("image", cursor.getString(3));
  12.         map.put("intro", cursor.getString(4));
  13.         tmplist_db.add(map);
  14.         cursor.moveToNext();
  15. }
  16. cursor.close();
  17. dbhelper.close();
複製代碼
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

14
 樓主| yuno5420 | 收聽TA | 只看該作者
發表於 2011-12-5 23:50
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

15
ploglin | 收聽TA | 只看該作者
發表於 2011-12-6 10:18
當然也可以呀~~
但首先你要學怎麼操作 sqlite ,這邊有簡單的範例 http://developer.android.com/guide/topics/data/data-storage.html#db

將資料 insert 到 sqlite 之後,再去讀出來就可以了。
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

12
返回列表 發新帖
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則