显示ISO-8859-1恩在的WebView $ C $镉含量 [英] Displaying iso-8859-1 encoded content in WebView
本文介绍了显示ISO-8859-1恩在的WebView $ C $镉含量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从获得我想在web视图中显示SQLite数据库HTML codeD的内容。我目前使用的:
I am obtaining HTML coded content from an SQlite database that I would like to display in a WebView . I am currently using:
public class ShowAbstracts extends Activity {
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
if (extras != null) {
String body = extras.getString(DatabaseHelper.KEY_BODY);
WebView webview = new WebView(this);
setContentView(webview);
String summary = "<html><body> "+body+" </body></html>";
webview.loadData(summary, "text/html", "iso-8859-1");
}
}
}
它的工作原理,它会打开一个网页视图,并显示的内容,但我得到奇怪的字符和一些内容,它只是崩溃。数据库是ISO-8859-1 EN codeD。
有什么办法照顾特殊字符在我的数据库内容并正确显示它们?
It works in that it opens a WebView and displays the contents but I get strange characters and for some content it just crashes. The Database is ISO-8859-1 encoded. Is there any way to take care of the special characters in my database content and display them properly?
非常感谢事先!
里克
推荐答案
成功!
解决这个是三样东西的组合:
Solving this was a combination of 3 things:
- URI编码字符串
- 粘贴头在HTML字符串,标识UTF-8编码
- 安装的LibreOffice这使得用于产生SQLite数据库的XLS文件被保存为UTF-8编码的CSV文件(据我可以从MS Office Excel中告诉是不可能的)。
public class ShowAbstracts extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
if (extras != null) {
String body = extras.getString(DatabaseHelper.KEY_BODY);
WebView webview = new WebView(this);
setContentView(webview);
String summary = "<?xml version='1.0' encoding='utf-8'?><html><body>"+body+" </body></html>";
String uri = Uri.encode(summary);
webview.loadData(uri, "text/html", "utf-8");
}
}
}
这篇关于显示ISO-8859-1恩在的WebView $ C $镉含量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文