如何在 android ImageView 中显示来自 <img> 标签的图像

How to display an image in android ImageView from the <img> tag

我有一个从 MySQL 数据库获取数据的应用程序。该数据包含图像 urls,我设法实现了一个 imageLoader class 以使用图像 url 显示图像。然而,在显示包含在获取的文本中并包装在 <img> 标记中的图像时,我遇到了死胡同。请协助我显示 post 内容中包含的图像。以下是获取的数据示例。

This is a sample post, you may choose to continue reading or not. <a href='http://website.com/post'><img src=' http://website.com/post.jpg'></a>
This is a sample post, you may choose to continue reading or not

根据上面的文字,如何在 android 图像视图中显示 http://website.com/post.jpg

如果您想做的只是从数据库返回的文本中提取图像 url,如下所示的内容就足够了:

int start = s.indexOf("<img src='")+10;
int end = s.indexOf("'",start);
String url = s.substring(start, end));

其中 s 是从数据库返回的字符串

我终于找到了解决问题的完美方法。使用 jsoup,我能够在我的字符串中获取 HTML 标签,而且我能够用我想要的任何内容替换整个 HTML 段。感谢您的意见,希望这个答案有时能对某人有所帮助。