Question

I have a WebView using following code:

WebView webView = new WebView(cont);
webView.loadData("Red 20%", "text/html", "utf-8");

It is having trouble showing the string. But if I remove the '%' character from the string it is showing properly. What is wrong with the code? How do I display '%' in WebView?

Was it helpful?

Solution

Simple:

WebView webView = new WebView(cont);
webView.loadData("Red 20%", "text/html", "utf-8");

You can see the special characters here: http://www.degraeve.com/reference/specialcharacters.php

OTHER TIPS

URL encode the %

20%25 should do the trick

An easier alternative is to use TextUtils.htmlEncode() for the strings you want to display.

WebView webView = new WebView(cont);
String s = TextUtils.htmlEncode("Red 20%");
webView.loadData(s, "text/html", "utf-8");

Instead of % you have to useits equevalent to show it in web. actually it is &#37 so that your code should change to

webView.loadData("Red 20%", "text/html", "utf-8"); 

You can replace "Red 20%" -> "Red 20 %"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top