Ephraim
Ephraim

Reputation: 8391

Displaying Images parsed from JSOUP in android?

I've been trying to develop an android app that parses through a specific (business's) website, and display the head image of the site on the top, news on the bottom, and have buttons below it that will open a new activity to display the schedule for the business, and any other information about the business. I decided to use JSOUP, which I am very new to, but I can't figure out how it is that I go about displaying images. I tried something like this, but it didn't work:

        ImageView image = (ImageView) findViewById(R.id.headImage);
        Document doc = Jsoup.connect("http://www.example.com/").get();
        Elements divs = doc.select("img");
        for (Element div : divs) {
            Log.d("web Stuff",div.text());

           text.setText(text.getText() + "\n" + div.text());
           Element myImage = div;
           String url = myImage.absUrl("src");
           image.setImageDrawable(Drawable.createFromPath(url));
        }

how am I supposed to correctly implement something like this?

Upvotes: 1

Views: 1922

Answers (2)

Saurabh Dixit
Saurabh Dixit

Reputation: 1

 Drawable drw =LoadImageFromWebOperations(image_url);
 im.setImageDrawable(drw);


private Drawable LoadImageFromWebOperations(String strPhotoUrl) 
{
     try
     {
            InputStream is = (InputStream) new URL(strPhotoUrl).getContent();
            Drawable d = Drawable.createFromStream(is, "src name");
            return d;
      }catch (Exception e) {
            System.out.println("Exc="+e);
            return null;
      }
    }

Upvotes: 0

Franziskus Karsunke
Franziskus Karsunke

Reputation: 5208

I would load the image in a new thread if you want to do it for more than one image.

public void run() {
    URL url = new URL(url);
    Bitmap bitmap = BitmapFactory.decodeStream(url.openStream());
}

when the Thread is finished you can set the image of the imageview.

image.setImageBitmap(bitmap);

Upvotes: 1

Related Questions