How do I set an alert based on the HTML Text in android
currently I'm pulling text from a website using
public String getText(String uri) {
HttpClient client1 = new DefaultHttpClient();
HttpGet request = new HttpGet(uri);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
try {
String response_str = client1.execute(request, responseHandler);
return response_str;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "";
}
}
and I get a bunch of HTML code that is filtered with Html.fromHtml()
which cleans up all the HTML text and leaves me with the dialog I want.
However t开发者_运维问答his method cannot let me set the title of the alert dialog because it only comes out as one string and cannot differentiate between whats in the parameters from the <body></body>
parameters. It also doesn't filter out some comments such as
<!--BODY{color:white; background-color:transparent;......
How can I delete the extra HTML text and separate the title portion from the main body of the text. Thank You
Take a look at Spannable string class.
"This is the interface for text to which markup objects can be attached and detached. Not all Spannable classes have mutable text; see Editable for that."
To parse HTML, use an HTML-Parser as there are some out there.
In the case that you control the formating/content of that pulled/desired HTML-Page, you'll want to switch from HTML to something better suited for your needs like a simple XML-Language or JSON.
精彩评论