2010-08-30 29 views
0
I have parse the url and i get the html contents i want to show that content as a web page then what can i do to show that html contents. I am using textView then it shows same html content with tags. 



I have following html content which i want to display in webView. It displays only 

**// Please** but its original output is not this. 

<br /><br />Read the handouts please for tomorrow.<br /><br /><!-- 
homework help 
homework help 
help with homework 
homework assignments 
elementary school 
high school 
middle school 
// --><font color="#60c000" size="4"><strong>Please!</strong></font> 


its original output is 

請閱讀明天的講義。在哪裏我把html內容在android中查看

請!

我有其他HTML也那裏是IMG的標籤,但這說明不了什麼

請建議我該如何解決這個問題

回答

3

如果你想使用的HTML編碼和視圖僅僅是內容,而HTML標記和太TextView的你已經在使用此語法java文件:

TextView textView = (TextViewPlus) findViewById(R.id.textViewId); 
     textView.setText(Html.fromHtml(getString(R.string.htmlString))); 

上述生產線將在string.xml文件和string.xml文件讀取字符串內容,你可以給HTML格式的內容,這樣的:

<string name="htmlString"><![CDATA[ 

<div> 
    <p>hello this can be you any content and even you can use the other html tags.</p> 
</div> 


]]></string> 

讓我提醒你的內容具有之間進行圍封:< [CDATA [......你的HTML代碼放在這裏........]]>

1

有兩種方法。或者去webview,它可以自動編碼HTML標籤,或者如果你想使用Textview你可以使用Html.fromHtml()方法可用Android ....然後將Text設置爲Textview。事情是這樣的

Textview.setText(Html.fromHtml(source)); 

也不像這個

Spanned t=Html.fromHtml("HTML String that needs to be displayed"); 
yourtextView.setText(t);