安卓系统:从它们的路径下载图像并在gridview中显示



我正在制作一个应用程序,我在其中解析了包含图像路径及其描述的xml响应,现在我必须从它们的路径下载图像,然后在gridview中显示图像.我尝试了我的链接,但找不到任何相关的内容。如有任何帮助,我们将不胜感激。

and the response is:
ImagePath: http://apsolutions.com/amazing/explore/a19.png

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

这是解决方案

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();
}

据我所知,您会得到一个url的数组列表。

  1. 你需要使用HttpUrlConnection或Apache客户端制作一个图像下载程序。(搜索lazyimage下载程序)。在中实现一个监听器,它可以在下载完成后调用函数。

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

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

最新更新