2011-09-05 36 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