how to display my content on a html page in android
I want to display my data's in a html page, I make a static html page in assest folder .but don't know how to insert my data's in that html page progr开发者_开发技巧ammatically.
You'll need to have a WebView in your activity. Then load the html into the webview, here are some instructions.
Loading an html page from an asset is relatively simple:
WebView webView = (WebView)view.findViewById(R.id.myWebView);
webView.loadUrl("file:///android_asset/index.html");
But to programatically alter the content of the page you'd have to first read the asset file into a string, insert your data with a string replace, or use java.text.MessageFormat.
Here's the code to get an inputstream from an asset:
AssetManager mgr = this.getAssets();
InputStream is = mgr.open("index.html");
BufferedInputStream in = new BufferedInputStream(is);
// read the contents of the file
Once you have your html string populated, you can programmatically set the content of the webview:
webView.loadData(htmlString, "text/html", "UTF-8");
精彩评论