Reputation: 87
I want to extract the url from the html code and set it as a string in a text view in my app, any help on how to do it?
<div class = "content">
<img src="http://static.truegamer.com/uploads/1720905/2577706-june24_20140625.jpg"></a>
</div>
and this is the java code
try {
// Connect to the web site
Document documentImage2 = Jsoup.connect(urls[0]).get();
// Using Elements to get the class data
Element img = documentImage2.select("div[class=content] img[src]").get(1);
// Locate the src attribute
String imgSrcImage2 = img.attr("src");
?????????
} catch (IOException e) {
e.printStackTrace();
}
Upvotes: 0
Views: 296
Reputation: 7376
you can try this:
Document documentImage2 = Jsoup.connect(urls[0]).get();
// Using Elements to get the class data
Element div = documentImage2.select("div[class=content]").get(1);
Document doc_i = Jsoup.parse(div.toString());
Elements image = doc_i.select("img");
String imgSrcImage2 = image.html();
Upvotes: 0
Reputation: 4388
I think your question is how to add a TextView and then set it's text to be the image source url.
Try this:
TextView txtView = (TextView) findViewById(R.id.image_src);
txtView.setText(imgSrcImage2);
image_src is the the id of the TextView element in your layout (xml file)
Upvotes: 1