2011-09-05 52 views
1

正在使用WebView to load HTML file,它存储在assets/www目录中。从Android动态更改HTML值

HTML文件是:

<!DOCTYPE HTML> 
<html> 
<head> 
<title>PhoneGap</title> 
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script> 
<script src="http://widgets.twimg.com/j/2/widget.js"></script> 
</head> 
<body> 
<script> 

new TWTR.Widget({ 
    version: 2, 
    type: 'profile', 
    rpp: 6, 
    interval: 6000, 
    title: '@palafo', 
    width: 250, 
    height: 300, 
    theme: { 
    shell: { 
     background: '#ad0000', 
     color: '#ffffff' 
    }, 
    tweets: { 
     background: '#ffffff', 
     color: '#444444', 
     links: '#ad0000' 
    } 
    }, 
    features: { 
    scrollbar: true, 
    loop: false, 
    live: true, 
    hashtags: true, 
    timestamp: true, 
    avatars: true, 
    behavior: 'all' 
    } 
}).render().setUser('CareerBuilder').start(); 

</script> 
</body> 
</html> 

此HTML文件加载Twitter页面中我的web视图,使用。

webview.loadUrl("file:///android_asset/www/twitter.html"); 

现在,我想在这种情况下,用户名动态更改用户名,这里是CareerBuilder网站,现在我想动态更改名字的时候我在我的ListView即CareerBuilder网站点击X或Y等。

如何做到这一点?

感谢

回答

1

我有,我用下面的代码相同的应用程序.....

InputStream is = getAssets().open("introduction.html"); 
      int size = is.available(); 

      // Read the entire asset into a local byte buffer. 
      byte[] buffer = new byte[size]; 
      is.read(buffer); 
      is.close(); 

      // Convert the buffer into a string. 
      str = new String(buffer); 

      str = str.replace("XXXX", days); 

变化HTML文件....

<html> 
    <head> 
     <meta name="viewport" content="width=300, user-scalable=no"> 
     <title>Intro</title> 
     <style type="text/css"> 
      body { 
       padding:0; 
       margin:0; 
       font-family: Helvetica; 
       font-size: 25px; 
       background-color:#000000; 
       color:#A4C639; 
      } 
      td { 
       text-align: center; 
} 
     </style> 
    </head> 
    <body style="width: 300px;"> 
     <table width="100%" style="margin-top: 5px;"> 
      <tr> 
       <td> 
        <b>Welcome to the Voting Card<font size="1">tm</font> App, only</b> 
        <br/> 
       </td> 
      </tr> 
      <tr> 
       <td> 
        <span style="font-size:130px;font-weight:bold;">XXXX</span> 
       </td> 
      </tr> 
      <tr> 
       <td> 
        <span style="font-size:18px;"> 
        Days Until the Nov. 6th, 2012 Presidential election. 
        <br/><br/> 
        Check back periodically to see what else the U.S. Congress in Washington, D.C. 
        is voting on and stay in contact with your elected officials. 
        <br/><br/> 
        For more information about VOTING CARDtm and its upcoming features visit us at 
        <br/><br/> 
        www.capitolgamescience.com 
        <br/><br/> 
        or email us at 
        <br/><br/> 
        [email protected] 
        <br/><br/> 
        Thank you for using our app, 
        <br/><br/> 
        Capitol Game Science Media, LLC 
        <br/> 
        <br/><br/> 
        We respect your privacy and abide by applicable U.S. privacy laws. 
        None of your personal information will be retained or recorded. 
        Your emails and web browsing will be conducted from your device. 
        </span> 
       </td> 
      </tr> 
     </table> 
    </body> 
</html> 
+0

它不是为我工作.. – Udaykiran

+0

最新问题?????? –

+0

我无法获得替换的东西,我试图通过在脚本中声明一个变量并使用它来替换它,但它不会将其更改为Undeclared .. – Udaykiran