Skip to content Skip to sidebar Skip to footer

Unable To Show Json Html Content Data In Textview In Android

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 ca

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

}

Solution 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


Solution 3:

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";
        final String baseUrl = "http://www.homeworknow.com/";
        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(baseUrl, html, mimeType, encoding, "");
    }

}// only thing for show image in webview from html give **base url** of image like this http://www.homeworknow.com/

Post a Comment for "Unable To Show Json Html Content Data In Textview In Android"