Вопрос

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 enter image description here

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));
Это было полезно?

Решение

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, "");
    }

}

Другие советы

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top