Webview显示html标签不是实际需要的数据?

时间:2011-10-24 04:26:49

标签: android android-emulator

emulator shows this output

我已解析数据并存储在字符串中并使用web-view加载它然后在模拟器中显示HTML标记。但是当我在另一台机器上运行相同的应用程序时,它会显示实际的网页。是模拟器还是其他问题?我已经给了互联网权限,还设置了代理设置。在模拟器浏览器中,所有网页都正常工作。请检查我的代码。

String vidushImg;
URL url=null; 

public void onCreate(Bundle savedInstanceState)

{

 super.onCreate(savedInstanceState);
 setContentView(R.layout.news); 
 Intent newsIntent=getIntent();
 vidushImg=newsIntent.getStringExtra("ss");
 showWeb();

}

private void showWeb() 
{
    WebView webview = new WebView(this); 
    setContentView(webview); 
    webview.getSettings().setJavaScriptEnabled(true); 
    Log.v("....hello....","");
    webview.loadData(vidushImg,"text/html","utf-8");

}


   The value of vidushImg-----> 
    <div style="text-align: center;"><span class="Apple-style-span" style="font-weight: normal; font-size: medium; "><img src="http://mobileecommerce.site247365.com/admin/assetmanager/images/gns_header.jpg" alt="" align="middle" border="1px" height="90" width="550"></span></div><span class="Apple-style-span" style="color: rgb(105, 105, 105); font-family: Verdana; font-size: 13px; font-weight: normal; "><br><div style="text-align: center;">Yes we are coming at E & I? Are you?</div></span><br><h1 style="font-weight: bold; "><span style="font-family: Verdana; font-size: 14pt; ">News for the day...</span></h1><span style="color: rgb(105, 105, 105); "><span style="font-family: Tahoma; font-size: 10pt; ">Template Mobile Sites for IC: <a href="http://icmobilesite.vidushiinfotech.net/">http://icmobilesite.vidushiinfotech.net/</a></span><br><span class="Apple-style-span" style="font-family: Tahoma; font-size: 13px; color: rgb(105, 105, 105); ">Promotional valid till 30 Sept 2011: MOBILE WEBSITE (Base Product Mobile CMS) for JUST $159<br></span></span><br><span style="font-family: Tahoma; font-size: 10pt; color: rgb(105, 105, 105); ">Mobile Template link: </span><a href="http://newsletter.vidushiinfotech.net/Mobilesite/"><span class="Apple-style-span" style="font-size: 15px; font-family: Calibri, sans-serif; color: rgb(105, 105, 105); ">http://newsletter.vidushiinfotech.net/Mobilesite/</span><br></a><span style="font-size: 10pt; font-family: Tahoma; "><span style="font-size: 10pt; "><br><span style="color: rgb(105, 105, 105); ">With the promotion on Business Edge and eFusion still running successful in e market place - $ 499</span><br><span style="color: rgb(105, 105, 105); ">Check out some of the latest site launch on: </span><br><br><span style="color: rgb(105, 105, 105); font-weight: bold; ">http://www.randallcontracting.co.uk/Pages/Default.aspx </span><br><br><span style="color: rgb(105, 105, 105); font-size: 10pt; "><span style="font-weight: bold; ">Category</span>: Building & Construction</span><br></span><br></span><div style="color: rgb(105, 105, 105); text-align: left; "><span style="font-size: 10pt; font-family: Tahoma; ">Description: WELCOME TO RANDALL CONTRACTING Randall Contracting is a family-run contracting SME which has been servicing London and the South East since 1956. Working closely with our Clients and external Design Consultants, we place great emphasis on a safe, positive, practical and common sense approach to our projects. Our delivery methods have resulted in an extensive volume of repeat business from both Private and Public Sectors. Safety and Environmental concerns are a high priority on all our contracts and we continually strive to source innovative working methods and solutions. Our equipment is regularly updated and maintained to ensure minimal environmental impact.</span><br><br></div><span style="color: rgb(105, 105, 105); font-weight: bold; font-family: Tahoma; "><span style="font-size: 10pt; "><br></span></span><br>

1 个答案:

答案 0 :(得分:2)

仅供参考,其工作正常如下:

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class DemoExampleActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        String strWeb = "<div style=\"text-align: center;\"><span class=\"Apple-style-span\" style=\"font-weight: normal; font-size: medium; \"><img src=\"http://mobileecommerce.site247365.com/admin/assetmanager/images/gns_header.jpg\" alt=\"\" align=\"middle\" border=\"1px\" height=\"90\" width=\"550\"></span></div><span class=\"Apple-style-span\" style=\"color: rgb(105, 105, 105); font-family: Verdana; font-size: 13px; font-weight: normal; \"><br><div style=\"text-align: center;\">Yes we are coming at E & I? Are you?</div></span><br><h1 style=\"font-weight: bold; \"><span style=\"font-family: Verdana; font-size: 14pt; \">News for the day...</span></h1><span style=\"color: rgb(105, 105, 105); \"><span style=\"font-family: Tahoma; font-size: 10pt; \">Template Mobile Sites for IC: <a href=\"http://icmobilesite.vidushiinfotech.net/\">http://icmobilesite.vidushiinfotech.net/</a></span><br><span class=\"Apple-style-span\" style=\"font-family: Tahoma; font-size: 13px; color: rgb(105, 105, 105); \">Promotional valid till 30 Sept 2011: MOBILE WEBSITE (Base Product Mobile CMS) for JUST $159<br></span></span><br><span style=\"font-family: Tahoma; font-size: 10pt; color: rgb(105, 105, 105); \">Mobile Template link: </span><a href=\"http://newsletter.vidushiinfotech.net/Mobilesite/\"><span class=\"Apple-style-span\" style=\"font-size: 15px; font-family: Calibri, sans-serif; color: rgb(105, 105, 105); \">http://newsletter.vidushiinfotech.net/Mobilesite/</span><br></a><span style=\"font-size: 10pt; font-family: Tahoma; \"><span style=\"font-size: 10pt; \"><br><span style=\"color: rgb(105, 105, 105); \">With the promotion on Business Edge and eFusion still running successful in e market place - $ 499</span><br><span style=\"color: rgb(105, 105, 105); \">Check out some of the latest site launch on: </span><br><br><span style=\"color: rgb(105, 105, 105); font-weight: bold; \">http://www.randallcontracting.co.uk/Pages/Default.aspx </span><br><br><span style=\"color: rgb(105, 105, 105); font-size: 10pt; \"><span style=\"font-weight: bold; \">Category</span>: Building & Construction</span><br></span><br></span><div style=\"color: rgb(105, 105, 105); text-align: left; \"><span style=\"font-size: 10pt; font-family: Tahoma; \">Description: WELCOME TO RANDALL CONTRACTING Randall Contracting is a family-run contracting SME which has been servicing London and the South East since 1956. Working closely with our Clients and external Design Consultants, we place great emphasis on a safe, positive, practical and common sense approach to our projects. Our delivery methods have resulted in an extensive volume of repeat business from both Private and Public Sectors. Safety and Environmental concerns are a high priority on all our contracts and we continually strive to source innovative working methods and solutions. Our equipment is regularly updated and maintained to ensure minimal environmental impact.</span><br><br></div><span style=\"color: rgb(105, 105, 105); font-weight: bold; font-family: Tahoma; \"><span style=\"font-size: 10pt; \"><br></span></span><br>";
        WebView webview = new WebView(this); 
        setContentView(webview); 
        webview.getSettings().setJavaScriptEnabled(true); 
        webview.loadData(strWeb,"text/html","utf-8");
    }
}

enter image description here

更新

  1. 在AndroidManifest.xml文件中添加<uses-permission android:name="android.permission.INTERNET"/>权限。
  2. 为什么要在showWeb()方法中再次调用setContentView()方法,而是直接在新闻xml布局文件中取一个WebView并引用它。
  3. 在其他情况下, Check your Internet Connection