Unable to show Json html content data in textview in android

久未见 提交于 2019-12-11 11:35:15

问题


Right now i am trying to display images and texts from one html content in text-view in android. Actually i am getting those html contents from json,but the help of below code i can only able to show the available texts like the below image

and unable to show the images.Can any one tell me how to display both images and texts from html content?

suggestions please

Thanks for your precious time!..

String  htmlcontent = "\u003ch3 style=\"text-align: justify;\"\u003e \u003cspan style=\"color: #800080;\"\u003eJourneys Magazine -                     Sports                          Best of Rage\r\n\u003c/span\u003e\u003cspan style=\"color: #800080;\"\u003e New Ireland Journey                     Magazine                     Magazine\u003c/span\u003e\u003c/h3\u003e\r\n\u003cp style=\"text-align: justify;\"\u003e\u003cimg alt=\"\" src=\"http://dev.postcourier.com.pg/wp-content/uploads/2013/08/Journeys-NIP_-Front-cover.jpg\" width=\"180\" height=\"335\" /\u003e \u003cimg alt=\"\" src=\"http://dev.postcourier.com.pg/wp-content/uploads/2013/08/Sports-Magazine-Cover2.jpg\" width=\"184\" height=\"336\" /\u003e \u003cimg alt=\"\" src=\"http://dev.postcourier.com.pg/wp-content/uploads/2013/08/BOR_front-cvr.jpg\" width=\"184\" height=\"335\" /\u003e\u003c/p\u003e\r\n\u003cp style=\"text-align: justify;\"\u003e \u003c/p\u003e";

txt_date.setText(Html.fromHtml(htmlcontent));

回答1:


TextView is used to show Text only. @Manick you can only show text in TextView, if you want to show the html page(with images and complete page), you have to use a Webview, then when you will get the json, you have to save it in .html file, and then give that file to webview to show that page or you can show html content in the Webview by using this example code. html string will be your JSON response.

Here is the example:-

public class SimpleMusicStream extends Activity {
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);

        WebView wv = (WebView) findViewById(R.id.WebView01);        

        final String mimeType = "text/html";
        final String encoding = "UTF-8";
        String html = "<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>" +
                "<img src='http://www.homeworknow.com/hwnow/upload/images/tn_star300.gif'  />";


        wv.loadDataWithBaseURL("", html, mimeType, encoding, "");
    }

}



回答2:


String htmlcontent = "\u003ch3 style=\"text-align: justify;\"\u003e \u003cspan style=\"color: #800080;\"\u003eJourneys Magazine - Sports Best of Rage\r\n\u003c/span\u003e\u003cspan style=\"color: #800080;\"\u003e New Ireland Journey Magazine Magazine\u003c/span\u003e\u003c/h3\u003e\r\n\u003cp style=\"text-align: justify;\"\u003e\u003cimg alt=\"\" src=\"http://dev.postcourier.com.pg/wp-content/uploads/2013/08/Journeys-NIP_-Front-cover.jpg\" width=\"180\" height=\"335\" /\u003e \u003cimg alt=\"\" src=\"http://dev.postcourier.com.pg/wp-content/uploads/2013/08/Sports-Magazine-Cover2.jpg\" width=\"184\" height=\"336\" /\u003e \u003cimg alt=\"\" src=\"http://dev.postcourier.com.pg/wp-content/uploads/2013/08/BOR_front-cvr.jpg\" width=\"184\" height=\"335\" /\u003e\u003c/p\u003e\r\n\u003cp style=\"text-align: justify;\"\u003e \u003c/p\u003e";

WebView webView=new WebView(this); webView.loadData(htmlContent,"text/html","UTF-8");

Thats it



来源:https://stackoverflow.com/questions/25032518/unable-to-show-json-html-content-data-in-textview-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!