0

I am making an app in which i have parsed the xml response which contain image path and its description and now i have to download images from their path and then show images in gridview.I tried my links but couldnot found anything relevant.Any help regarding this will be appreciated.

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 Answers2

0

Here is solution..

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();
}
Nikunj Patel
  • 21,853
  • 23
  • 89
  • 133
  • when i parse the response i get the url in arraylist, now i want to know that how to use that arraykist to get images –  Mar 19 '12 at 07:49
0

From what I understand you get an arraylist of urls.

  1. u need to make an image downloader using either HttpUrlConnection or Apache Client. (Search for lazyimage downloader). Implement a listener in this which can call a function once download is complete.

  2. Send requests to receive the images.

  3. Make viewholders for your gridview and in your viewholder, implement the listener for ure image downloader. In the listener set the image in your imageview.

Shubhayu
  • 13,402
  • 5
  • 33
  • 30