To remove HTML Tags - android

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)?

Related

Android Html.fromHtml function auto converts undesired text into hyperlinks

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());

HTML in TextView

The response of a web service is the following :
<span style="color:#DDFFEE;">You have to pay you bil before <b>12 june 2012</b> for your informations.</span></br></br> You have already a large time.
I want to display this in a TextView.
I can't just simply put the response below in a String and applicate
myTextView.setText(Html.fromHtml(response));
It doesn't work because it can't be a String.
How can I do this dynamically please ?
You just need to put the String you get as a response, inside the fromHtml call, if it's not a String, maybe you just need to append .toString() to it, to get a String..
textView.setText(Html.fromHtml("<h2>This is HTML</h2>"));
You need to use Html.fromHtml() to use HTML in your XML Strings. Simply referencing a String with HTML in your layout XML will not work.
myTextView.setText(Html.fromHtml("<h2>Title</h2><br><p>Description here</p>"));
here : Similar question

Setting Danish Character Text

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&oslash ;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!

Android getting multiline strings from XML problems

I am trying to print a text which is fetched from the server. What is the best way to escape all special characters and print safely?
Because the string which is fetched from the server is entered by user an stores it on database. So there is a possibility use <?php ?> , & etc which may cause errors. I have tried < > which solved this problem.
But when setText() the string to an EditText the string gets truncated after &
So I need a best solution in which the text entered by the user will save safely in the database and retrieve the multi-line string with special characters safely.
What is the best way to do this?
I think you should use StringBuilder instead of simply reading the text from XML.
Follow these steps :
1) For each new tag in XML (in startElement) , create a String builder
2) Append the text to same StringBuilder in reading from Character method.
3) At last, assign that StringBuider to some String at the End of the tag (in EndElement).
Hope this will give you some idea to solve the problem .
Try ...!!!
Anyways the problem solved by using URLDecode.decode() at the app and urldecode(),stripslashes() at the server side.
Dont know whether this is the perfect solution, but it worked for me.

how to use HTML tags to format text in an EditText in android

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>"));

Categories

Resources