Android:从路径下载图像并在gridview中显示

时间:2012-03-19 07:38:55

标签: android image

我正在创建一个应用程序,其中我已经解析了包含图像路径及其描述的xml响应,现在我必须从路径下载图像,然后在gridview中显示图像< /strong>。我尝试了我的链接,但找不到任何相关内容。对此有任何帮助将不胜感激。

and the response is:

ImagePath: http://apsolutions.com/amazing/explore/a19.png

03-19 14:57:13.460:I / System.out(13878):ImagePath:http://apsolutions.com/amazing/explore/a16.png 03-19 14:57:13.460:I / System.out(13878):ImagePath:http://apsolutions.com/amazing/explore/a15.png 03-19 14:57:13.460:I / System.out(13878):ImagePath:http://apsolutions.com/amazing/explore/a13.png 03-19 14:57:13.460:I / System.out(13878):ImagePath:http://apsolutions.com/amazing/explore/a12.png 03-19 14:57:13.460:I / System.out(13878):ImagePath:http://apsolutions.com/amazing/explore/a11.png 03-19 14:57:13.460:I / System.out(13878):ImagePath:http://apsolutions.com/amazing/explore/a10.png 03-19 14:57:13.460:I / System.out(13878):ImagePath:http://apsolutions.com/amazing/explore/a9.png 03-19 14:57:13.460:I / System.out(13878):ImagePath:http://apsolutions.com/amazing/explore/a8.png 03-19 14:57:13.460:I / System.out(13878):ImagePath:http://apsolutions.com/amazing/explore/a7.png 03-19 14:57:13.460:I / System.out(13878):ImagePath:http://apsolutions.com/amazing/explore/a6.png

2 个答案:

答案 0 :(得分:0)

以下是解决方案..

URL url = new URL ("url/anImage.png");
InputStream input = url.openStream();
try {

    String storagePath = Environment.getExternalStorageDirectory();
    OutputStream output = new FileOutputStream (storagePath + "/myImage.png");
    try {
        byte[] buffer = new byte[aReasonableSize];
        int bytesRead = 0;
        while ((bytesRead = input.read(buffer, 0, buffer.length)) >= 0) {
            output.write(buffer, 0, bytesRead);
        }
    } finally {
        output.close();
    }
} finally {
    input.close();
}

答案 1 :(得分:0)

根据我的理解,你会得到一个网址的arraylist。

  1. 您需要使用HttpUrlConnection或Apache Client创建图像下载程序。 (搜索lazyimage下载器)。在此实现一个监听器,一旦下载完成就可以调用一个函数。

  2. 发送接收图片的请求。

  3. 为您的gridview制作视图,并在视图中为视图下载器实现侦听器。在监听器中,在imageview中设置图像。