本文介绍了来自URL的HTML的Android TextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直试图让一个TextView可以从URL显示我的HTML,但是我看到的所有示例都使用了字符串,例如
Ive been trying to get a TextView working to display my HTML from a url but all the examples ive seen use a string e.g
String htmltext = "<h2>Title</h2><br><p>Description here</p>";
myTextView.setText(Html.fromHtml(htmltext));
但是我想从我运行的网页上显示.如果我将 htmltext 更改为"www.example.com ,但不会显示内容.
But i want to display from a webpage that i run. If i change htmltext to "www.example.com but that is displayed not the content.
我肯定会有很多人说使用webview.我拥有并且看起来就像浏览器一样.
Im sure many will say use webview. I have and looks just like a browser.
推荐答案
最后,我使用JSoup来完成任务.稍后再发布代码
In the end I used JSoup to do my task. Will post code later
new Thread(new Runnable() {
@Override
public void run() {
try {
//get the Document object from the site. Enter the link of site you want to fetch
Document document = Jsoup.connect("http://www.mywebsite.com.au/message.html").get(); // this is the website string
//Get the text we want
title = document.select("h2").text().toString();
//set the title of text view
//Run this on ui thread because another thread cannot touch the views of main thread
runOnUiThread(new Runnable() {
@Override
public void run() {
//set both the text views
titleText.setText(title);
titleText.setMovementMethod(new ScrollingMovementMethod());
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
这篇关于来自URL的HTML的Android TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!