This is an old and already accepted question, however I am sure that the problem can be solved more elegantly using javascript.
Store the html file in the folder with your assets and surround the text you want to replace with div elements with unique identifiers.
<html> <head> ... <head> <body> Static text <div id="replace1">replace me</div> <div id="replace2">replace me too</div> More static text ... </body> </html>
Now create a javascript function that will replace the innerHtml div with id:
function replace(id, newContent) { document.getElementById(id).innerHTML = newContent; }
This function will be best placed directly in the html file, update the <head> section to look like this:
<head> ... <script type="text/javascript"> function replace(id, newContent) { document.getElementById(id).innerHTML = newContent; } </script> </head>
Now we need to call the javascript function from the Android api web application:
WebView helpView = (WebView)findViewById(R.id.helpView); helpView.getSettings().setJavaScriptEnabled(true); helpView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); view.loadUrl("javascript:replace('replace1', 'new content 1')"); view.loadUrl("javascript:replace('replace2', 'new content 2')"); } }); helpView.loadUrl("file:///android_asset/help.html");
Using this, you will avoid reading potentially large data into memory and unnecessarily perform expensive operations.
source share