0

我必须从以下 URL 获取文本:http: //diavolivicenza.blogspot.it/2013/10/il-ritorno-di-michele-valbusa-07102013.html并且我必须仅在布局中显示文本和图像。例如,我想更改文本的颜色或大小。我只想要文本和图像。谢谢

4

2 回答 2

0

执行此操作有两个步骤 1)在 AsyncTask 中发出 Http 请求 2)解析您将从该 url 获得的响应,如下所示

while((text = stream.readLine()) != null )
{
    result += text ;
}
textView.setText(Html.fromHtml(result));
于 2013-10-12T10:26:22.940 回答
0

像这样试试

while ((line = reader.readLine()) != null) {
    result += line + "\n";
}
HTML = result;

试试这个:

outtext.setText(Html.fromHtml(HTML));

而不是在主线程中执行网络操作,我建议您使用 AsyncTask 在单独的线程中执行此操作

用这个,

private void getHTML() throws ClientProtocolException, IOException 

{
    HttpClient httpClient = new DefaultHttpClient();
    HttpContext localContext = new BasicHttpContext();
    HttpGet httpGet = new HttpGet("http://artistone.appone.nl/api/biografie.php?dataid=998"); //URL!
    HttpResponse response = httpClient.execute(httpGet, localContext);
    String result = "";

    BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

    String line = null;
    while ((line = reader.readLine()) != null) {
        result += line + "\n";
        HTML = result;
    }

}
于 2013-10-12T10:08:55.593 回答