2012-12-01 72 views
0

可能重複:
how to implement lazy loading of images in gridview在Android中從url獲取多個圖像?

如何從Android中使用可繪製網址提取多張圖片?

private Drawable LoadImageFromWebOperations(String url) { 
     try { 
      InputStream is = (InputStream) new URL(url).getContent(); 
      Drawable d = Drawable.createFromStream(is, "icon"); 
      return d; 
     } catch (Exception e) { 
      System.out.println("Exc=" + e); 
      return null; 
     } 
    } 

我使用這個函數返回繪製的圖像,但我沒有得到如何綁定圖像的GridView的列表..

請幫助我。

+0

試試看這個[鏈接](https://github.com/nostra13/Android-Universal-Image-Loader)。它爲你開箱即用很多工作 –

回答

1

,只需提供網址爲 「imgaeUrl」 字段

URL url = new URL(imageUrl); 
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 

InputStream is = connection.getInputStream(); 
Bitmap img = BitmapFactory.decodeStream(is); 

imageView.setImageBitmap(img); 

,並設置ImageView的

+0

這段代碼適用於單個圖像..對圖像數組做什麼? –

+0

@shivanipatel第一次全部進入列表清單網址;然後開始for循環for(int i = 0; i QuokMoon

+0

。 i ++){ \t \t \t \t \t \t HashMap hm = imageList.get(1); \t \t \t \t \t \t \t \t \t \t \t \t drawable.add(LoadImageFromWebOperations(hm.get(TAG_IMAGE))); \t \t \t \t \t \t Toast.makeText(getApplicationContext(),hm.get(TAG_IMAGE),Toast.LENGTH_LONG).show(); \t \t \t \t \t} –