0

I have an application which fetches data from a MySQL database. That data contains image urls which I have managed to implement an imageLoader class to display the image using the images url. I have however hit a dead end when it came to displaying an image which is contained in the text fetched and is wrapped in the <img> tag. Kindly assist me in displaying an image contained in the post content. Below is a sample of the data fetched.

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

From the above text, How do I display http://website.com/post.jpg in an android imageview?

Biko
  • 332
  • 3
  • 15

2 Answers2

0

If all you want to do is extract the image url from the text returned from the database something like the following will suffice:

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

where s is the string returned from the database

QuantumTiger
  • 970
  • 1
  • 10
  • 22
  • Yes, will this also remove the entire image code from the string i.e remove `` from the string – Biko Nov 30 '15 at 12:16
  • No. Is that what you want? Or do you need the two urls in separate strings? – QuantumTiger Nov 30 '15 at 12:22
  • Nop, I neew to get the image url as above so that I can use it in my image loader and also remove the code block from the text as the reader does need to read it – Biko Nov 30 '15 at 12:26
0

I finally got a perfect solution for my problem. Using jsoup, I am able to get the HTML tags in my string and also I am able to replace the entire HTML segment with whatever content I want. Thanks for your input and hope this answer will help someone sometime.

Biko
  • 332
  • 3
  • 15