开发者

where i put html content in android to view

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 />R开发者_C百科ead 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 

Read the handouts please for tomorrow.

Please!

I have other html also where there is a tag of img but this shows nothing

Please Suggest me how to solve this problem


If you want to use the html coding and view just the content without the html tag and that too in textview you have to use this syntax in the java file :

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

the above line will fetch the string content in the string.xml file and in string.xml file you can give the content in html format , something like this :

 <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>

let me remind you the content has to be inclosed between: <[CDATA[......your html code goes here........]]>


There are two ways. Either go for a webview which can encode HTML tags automatically or if you want to use Textview you can use Html.fromHtml() method available on Android....Then set the Text to your Textview. Something like this

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

or Even like this

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜