0

With Android Studio I have a code that displays images from a direct URL. I want that displays all the images from a site (they are item called <enclosure/>) and put that in my Custom ListView. So I get the String of the URLs where is present the image and then show it by the code below but I get nothing. Can you help me?

TextView txtImage = (TextView)rowView.findViewById(R.id.item_image);
    txtImage.setText(web.get(position).getEnclosure());
    txtImage.setTypeface(myTypeface);

    ImageView img = (ImageView) rowView.findViewById(R.id.enclosure);

    try {
        URL url = new URL(context.getString(R.id.item_image));
        HttpGet httpRequest = null;

        httpRequest = new HttpGet(url.toURI());

        HttpClient httpclient = new DefaultHttpClient();
        HttpResponse response = (HttpResponse) httpclient
                .execute(httpRequest);

        HttpEntity entity = response.getEntity();
        BufferedHttpEntity b_entity = new BufferedHttpEntity(entity);
        InputStream input = b_entity.getContent();

        Bitmap bitmap = BitmapFactory.decodeStream(input);

        img.setImageBitmap(bitmap);

    } catch (Exception ex) {

    }
Rick
  • 3,943
  • 6
  • 33
  • 45

1 Answers1

2

This is all you need to do:

URL url = new URL("http://image10.bizrate-images.com/resize?sq=60&uid=2216744464");
Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
imageView.setImageBitmap(bmp);

It's not recommended to do this on the UI thread, as it blocks, but you can do it in an AsyncTask.

Codeman
  • 12,157
  • 10
  • 53
  • 91
  • I don't need this. I need to download all the images that are in a site. I'm building an RSS app so I want to display the images – Rick Jan 08 '14 at 22:59
  • That's a scraper, something completely different from what you're asking. You'd have to go through and find all `` tags in the HTML and download them individually. That's really not what your question is asking at all. – Codeman Jan 08 '14 at 23:02
  • Check my edited answer and let me know if you have understood what I want to do – Rick Jan 08 '14 at 23:07
  • That's a completely different question. You have to go through and grab every image URL you want and display it using the method I showed here. – Codeman Jan 08 '14 at 23:09
  • Yore going to need a list of the URLs.. Can you retrieve them? – NightSkyCode Jan 09 '14 at 00:04
  • No, but could you explain the reason you voted down? I think my question is quite understanding about what I want to do – Rick Jan 09 '14 at 12:29
  • @user2675569 I didn't vote you down, but your original question is utterly different from the question you asked, and neither were formulated well or put much effort in. – Codeman Jan 09 '14 at 19:04
  • In fact then I edited it to explain better what I want to do. Isn't it clear yet? – Rick Jan 09 '14 at 19:32
  • No, it's really not. The answer you want is not the question you're asking at all. – Codeman Jan 09 '14 at 19:35
  • Sorry but I don't know speak english good and I don't know how to let you understand, I don't know how to change my question or delete it – Rick Jan 09 '14 at 19:45
  • You should ask the new question and make it the question you're actually trying to ask - how to download a set of images from the website. A 2nd question would be how to display a set of images, but that's already been answered. – Codeman Jan 09 '14 at 19:51