无法显示在android系统的TextView的Json html内容数据 [英] Unable to show Json html content data in textview in android

查看:245
本文介绍了无法显示在android系统的TextView的Json html内容数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我试图从文本视图中的一个HTML内容在Android中显示图像和文字。其实我正从JSON的HTML内容,但低于code的帮助下,我只能能够显示像下面的图片可用文本

和无法显示images.Can任何一个告诉我如何从HTML内容同时显示图像和文字?

建议请

感谢您的precious时间!..

 字符串htmlcontent =\\ u003ch3风格= \\文本对齐:理由; \\\\ u003e \\ u003cspan风格= \\COLOR:#800080; \\\\ u003eJourneys杂志 - 体育最佳的愤怒\\ r \\ n \\ u003c / SPAN \\ u003e \\ u003cspan风格= \\COLOR:#800080; \\\\ u003e新的爱尔兰之旅杂志杂志\\ u003c / SPAN \\ u003e \\ u003c / H3 \\ u003e \\ r \\ n \\ u003cp风格= \\文本对齐:理由; \\\\ u003e \\ u003cimg ALT = \\\\SRC = \\http://dev.postcourier.com.pg/wp-content/uploads/2013/08/Journeys -NIP_-前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风格= \\文本对齐:理由; \\\\ u003e \\ u003c / p \\ u003etxt_date.setText(Html.fromHtml(htmlcontent));


解决方案

的TextView 用于显示的仅文本
@Manick只能在TextView中显示的文本,如果你想显示HTML页面(带图像和完整的页面),你必须使用一个网页视图,然后当你将得到JSON,你有将其保存在.html文件,然后给该文件的WebView表明页面或者您可以通过使用这个例子code显示web视图HTML内容。 HTML字符串将是你的JSON响应。

下面是例子: -

 公共类SimpleMusicStream延伸活动{
    @覆盖
    公共无效的onCreate(捆绑冰柱){
        super.onCreate(冰柱);
        的setContentView(R.layout.main);        WV的WebView =(的WebView)findViewById(R.id.WebView01);        最后弦乐mime类型=text / html的;
        最终字符串编码=UTF-8;
        字符串的html =< BR />< BR />阅读讲义请明天< BR />< BR /><! - 作业辅导功课+
                功课作业帮助帮助赋值小学中学中学+
                // - >!<字体颜色='#60c000大小=4><强>请< / STRONG>< / FONT>中+
                < IMG SRC =HTTP://www.homeworknow.com/hwnow/upload/images/tn_star300.gif/>中;
        wv.loadDataWithBaseURL(,HTML,mime类型,编码,);
    }}

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

解决方案

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

}

这篇关于无法显示在android系统的TextView的Json html内容数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆