Android 台灣中文網

打印 上一主題 下一主題

[求助] ListView 顯示問題

[複製連結] 查看: 2646|回覆: 13|好評: 0
跳轉到指定樓層
樓主
yuno5420 | 收聽TA | 只看該作者 回帖獎勵 |正序瀏覽 |閱讀模式
發表於 2011-11-23 16:40

馬上加入Android 台灣中文網,立即免費下載應用遊戲。

您需要 登錄 才可以下載或查看,沒有帳號?註冊

x
本帖最後由 yuno5420 於 2011-11-24 00:53 編輯

請問要怎麼把 2個 EditText 的資料 在SQL拿出顯示在 ListView 同一個欄位阿

試了很多次 都不能
「用Android 就來APK.TW」,快來加入粉絲吧!
Android 台灣中文網(APK.TW)
熱門小遊戲推薦
收藏收藏 分享分享 分享專題
用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)
回覆 支持 反對

使用道具 舉報

14
 樓主| yuno5420 | 收聽TA | 只看該作者
發表於 2011-12-5 23:50
用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)
回覆 支持 反對

使用道具 舉報

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

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

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

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


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

使用道具 舉報

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)
回覆 支持 反對

使用道具 舉報

10
 樓主| yuno5420 | 收聽TA | 只看該作者
發表於 2011-12-2 17:36
本帖最後由 yuno5420 於 2011-12-2 17:38 編輯

有阿  好像沒PO到

            ArrayList<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
        
        SimpleAdapter adapter = new SimpleAdapter(this, list, R.layout.list,
                        
        new String[]{SQLiteHelper.FIELD_TEXT,SQLiteHelper.FIELD_MYDATE},
                        

        new int[]{R.id.listTextView1, R.id.listTextView2});

            
            myListView.setAdapter(adapter);



我按儲存的時候  他會顯示一片黑耶
沒東西@@
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

9
ploglin | 收聽TA | 只看該作者
發表於 2011-12-1 21:14
你的 listview 有下 setAdapter 嗎?
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

8
 樓主| yuno5420 | 收聽TA | 只看該作者
發表於 2011-12-1 11:25
是這樣子嗎?  但是他還是沒辦法顯示

ArrayList<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
            
            SimpleAdapter adapter = new SimpleAdapter(this, list, R.layout.list,
                           
            new String[]{SQLiteHelper.FIELD_TEXT,SQLiteHelper.FIELD_MYDATE},
                             

            new int[]{R.id.listTextView1, R.id.listTextView2});
          

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

使用道具 舉報

7
ploglin | 收聽TA | 只看該作者
發表於 2011-12-1 11:09
不能直接把DB的Cursor丟進去adapter,必需將DB查詢的結果,轉換成ArrayList的方式。
例如
ArrayList<HashMap<String,Object>> 的型態
new String[] 對應的就是 HashMap 中 String 的位置
new int[] 對應的就是 resource id 的部份
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則