JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java ME、Google Android 平台與 JavaCard 討論區 » Android  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
作者 請問有什麼方法用自訂的listview加載SQLite裡的圖片?
pdyurfof





發文: 3
積分: 0
於 2011-03-08 17:10 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
自訂的listview裡有兩個textview和一個imageview,
從資料庫讀出來後,textview都有正確顯示,
但是圖片卻都是空白,
請問圖片是需要轉型還是怎樣呢?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
if (c != null) {
      while (c.moveToNext()) {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("ItemText", c.getString(3));
 
        byte[] buf;
        buf = c.getBlob(4);
        Bitmap bmp = BitmapFactory.decodeByteArray(buf, 0, buf.length);
        Drawable drawable = new BitmapDrawable(bmp);
           
        map.put("ItemImage",drawable);  
        map.put("ItemText2", c.getString(10));        
        listItem.add(map);        
      }
}


reply to postreply to post
作者 Re:請問有什麼方法用自訂的listview加載SQLite裡的圖片? [Re:pdyurfof]
bugbunney





發文: 51
積分: 0
於 2011-03-17 10:56 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
http://developer.android.com/reference/android/database/Cursor.html#getBlob(int)

剛剛看了一下文件

byte[] buf;
//the value of that column as a byte array.
//只是傳回某資料中column的內容byte array,應該是一個數值或字串值,不是一個bitmap
buf = c.getBlob(4);

//這裡的byte array應該是要bitmap本身的byte array
Bitmap bmp = BitmapFactory.decodeByteArray(buf, 0, buf.length);
Drawable drawable = new BitmapDrawable(bmp);

若是一個bitmap的file path請用decode file的方法來產圖吧


reply to postreply to post
» JWorld@TW »  Java ME、Google Android 平台與 JavaCard 討論區 » Android

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8