Convert html code into plain text - java

I am developing android application in which i want to convert html code in to plain text and display it in the editText. I use Jsoup.jar for that but it shrink the data. Like it just remove the tag.I will not got to the next line. Does any one has the solution to display html code in the plain text? Any help or suggestions are accepted. Thank you.

Use Html.fromHtml(htmltext).

Related

Insert Java code in a TextView

How to show Java code in a TextView?
you can store your code as HTML and parse HTML using HTML.fromHtml(String) to show styled HTML in your TextView. for more information, take a look at here

How to save HTML code in Sql Server database for correct display?

My website is just like Stack Overflow and under development. I am using plain textarea to take text input as I do not have any WMD editor like Stack Overflow's.
When I take HTML code as input and store it in database table in a text or nvarchar(max) column, it is stored successfully. But when I call that data for display, it displays the corresponding HTML page instead of that HTML code on screen. I am not able to resolve it. For better understanding I'm putting here input page and output page images of my website.
This is image of input page:
This is the image of output page:
What is going wrong here ?
One easy way is to replace
< with < and > with >
in the HTML string which you retrived and then display it on page.
Have you tried that ?
You need to escape the HTML so it's not interpreted by the browser. How to do that depends on the view technology you're using.
With JSP and JSTL the escaping is automatically done with <c:out value="${myString}"/>. If you're not using JSTL yet, now's the time to start (there's a lot of other helpful things in there too).
you can save the html codes just like text. You can use varchar(max) type column to save the html code in table. Display the code is depending the browser. But if you use nvarchar type that will cause problems in display.
Another possible solution is to replace the html tags before storing in database. What I did is :-
text=text.replaceAll("<", "<");
text=text.replaceAll(">", ">");
and then stored text in database and its working. Thanks to Bibin Mathew.

Creating a professional changelog using an AlertDialog (on Android in Java)

I am new to the Android app development (in Java) and I am also new to stackoverflow, so this is my first post/question. :)
Anyway, what I want, is, to create a more or less professional changelog using an AlertDialog. I wanted to set the message of it unsing strings. Ok, this worked well. But then it looked like this:
Text Text Text Text Text Text Text Text
But I want that it looks like this:
Text Text Text Text
Text Text
Text Text Text Text Text
For this I tried to add HTML tags to the string.xml file:<string name="About"><html><head>Text Text Text</head><body><b><p>Text Text Text Text Text Text </p></b></body></html></string>
(Just trying out what possibly could work)
And this worked for me only with bold-tags and stuff but I just couldn't figure out, how I can do it that my changelog looks like about the second example.
Can you help me, pls?
I'm looking forward to your suggestions!
PS: Sorry for the bad examples but I can't add images yet! :( and Sorry for my not so good English but I hope you could understand me! ;)
Either use \n in your String for a newline. Or use the paragraph tag, but I don't know if it is recognized. Like
<p>Texttext</p><p>second line</p>
u can use HTML as source eg. on .setText(String) / .append(String) via:
String fromHtml = Html.fromHtml("<u>html code</u>"))
for new line use escape char \n or in html < br />

Displaying xml in textarea without rendering htmlentities

I've been reading about this for a while now and can't find the solution.
This looks like the solution I need:
How to stop html textarea from interpreting html entities into their characters
But when I do this I just get in the textarea. What gives?
This is my first time trying to use jstl. Please help.
use jquery's text() method and assign it to text area.

Formatting Text

I need to format some text in JOptionPane.showMessageDialog. I need the text to be in tabular format
Example:
Operation Result
2 + 2 4
I have tried to use string.format() but it comes out ugly. Any suggestions would be helpful. Thanks
String.format would work well if you were using a fixed-width font (like a console output) but the message dialogs default to a variable-width font.
Luckily all labels in Swing support HTML formatting. All you have to do is wrap your string with HTML tags like <html> some text</html>. Then you could use an actual HTML table.
It seems like you got some number of data to be displayed. Using JDialog instead of JOptionpane is better to put number of data. Answer to your question can be found in the below link
http://forums.techguy.org/software-development/1051819-solved-help-java-tabular-format.html
You can pass a String containing the data in html code, you can try to do this format with a HTML table.

Categories

Resources