从android中的url获取多个图像?

时间:2012-12-01 07:06:56

标签: android

  

可能重复:
  how to implement lazy loading of images in gridview

如何使用Android中的Drawable从url中获取多个图像?

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 ..

请帮帮我。

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)