Android Html.fromHtml function auto converts undesired text into hyperlinks.
Here is my code:
String htmlContent= "corners of nail.It has to";
textViewContent.setTextHtml.fromHtml(htmlContent));
textViewContent.setText(comment.getContent());
In above code Html.fromHtml treats "nails.It" as a link and converts it into hyperlink.
Here is the result of converted string.
One of the solution which I could think is, put space after fullstop.
Is there any good solution?
You can try something like this.
textViewContent.setText( Html.fromHtml("YOUR DESIRED TEXT"));
textViewContent. setMovementMethod(LinkMovementMethod.getInstance());
Hope it helps.
Provide space between dot and second statement
String htmlContent= "corners of nail. It has to";
textViewContent.setTextHtml.fromHtml(htmlContent));
textViewContent.setText(comment.getContent());
Related
I would like to remove the tag in my android which is coming from an web response. And I dont want to use Html.fromHtml in my setText(), as I would not like the text to appear in the next line. Can anyone please suggest me an idea?
You can use replaceAll() function
ex:
html.replaceAll("&","");//remove ampersands
You can use trim on the String returned by Html.fromHtml for avoiding newline before and after the text.
Source: How to remove newlines from beginning and end of a string (Java)?
I'm looking for ways to convert text with spaces and symbols in html in android,
For Example:
"Hi this is my text" to "Hi%20this%20is%20my%20text"
Also with symbols...
Anyone knows any easy way to do it?
What I find is to convert html text to plain text.
Thanks in Advance......
What you need is not HTML but URL encoding, use URLEncoder.encode, see http://developer.android.com/reference/java/net/URLEncoder.html
For example, if your write
String s = URLEncoder.encode("Hi this is my text", "UTF-8");
variable s will contain Hi%20this%20is%20my%20text
Use TextUtils.htmlEncode() for this purpose.
I am getting some strings from json. My string contains special characters like "æ" from Næstved an many more like "ø" from køkken. But When I set Text these strings to ant textview, I get my strings printed in unusual way.
Example: For køkken I get kø ;kken.
I think I need to encode or decode my string somewhere but where I don,t know.
Please help.
Thanks in advance
The displayed version of your string represents an HTML encoded entity. You might want to verify that it is not coming in this way in your JSON data, but in any case, to decode it you can use the StringEscapeUtils.unescapeHtml4 method from Apache Commons Lang:
final String escaped = "køkken";
System.out.println(StringEscapeUtils.unescapeHtml4(escaped));
Output:
køkken
Did you check out the Latin Coding for your characters? I know the Ash character can be coded with æ and will show up æ in the browser.
Here is the a list of codes
Hope this helps!
my code looks like this
txtData=(EditText)findViewById(R.id.textbox);
txtData.setText(Html.fromHtml("<b><html></b>"));
as you can see i am trying to make HTML code appear in an EditText box. I am trying to use HTML tags using the Html.fromHtml() method to format the HTML code that appears in the box.
i need to find a way to escape the '<' and '>' tags around the word html from being processed by the fromHtml method. any suggestions on how to do this ?
try this:
txtData=(EditText)findViewById(R.id.textbox);
txtData.setText(Html.fromHtml("<b><html></b>"));
or
txtData=(EditText)findViewById(R.id.textbox);
txtData.setText(Html.fromHtml("<b><html></b>"));
Try this:
txtData.setText(Html.fromHtml("<b><html><b>"));
You should use
<
and
>
as in this example
txtData.setText(Html.fromHtml("<b><html></b>"));
String = " This is SAMPLE"
I want to increase the size of the SAMPLE alone in String to highlight, but need to be in a single string, this is to set in TextView.
Thanks in Advance.
textView.setText(Html.fromHtml("This is <font color='#707070' size='20'>
SAMPLE</font>"));
Try this:
String str = "This is <b>SAMPLE</b>";
yourTextView.setText(Html.fromHtml(str), BufferType.SPANNABLE);
Moreover, you may decorate your string (str) with html tags to alter the looks.
Or to highlight a part of text without using html stuff, read this
Use Html.fromHtml() in setText() of TextView. Supported Html Tags can be found here Html Tags Supported by TextView
I think this is possible if you pass the text as html with your highlighted part enclosed in html <bold> tag.
You have two options:
1, Format your string in HTML and use HTML.from("Your text");
2, Use spannable. A complete guide can find link here