在android中显示从JSOUP解析的图像?

发布于 2024-12-14 05:44:30 字数 685 浏览 3 评论 0原文

我一直在尝试开发一个Android应用程序,它可以解析特定的(企业)网站,并在顶部显示该网站的头部图像,在底部显示新闻,并在其下方有按钮,用于打开一个新的活动来显示业务时间表以及有关业务的任何其他信息。我决定使用 JSOUP,我对它很陌生,但我不知道如何显示图像。我尝试了这样的事情,但它不起作用:

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

我应该如何正确地实现这样的事情?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

二智少女 2024-12-21 05:44:30

如果您想为多个图像执行此操作,我会将图像加载到新线程中。

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

当线程完成后,您可以设置图像视图的图像。

image.setImageBitmap(bitmap);

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);
你又不是我 2024-12-21 05:44:30
 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;
      }
    }
 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;
      }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文