I am working with HTML and Unicode text that I'm querying from a database. I'm trying to convert it for proper display in a text view.
Here is the relevant code where I'm attempting the conversion:
ReviewView.setText(Html.fromHtml(URLDecoder.decode(cursor.getString(14), "UTF-8")).toString());
However, it's only partially working. Here is an example of the text I'm working with:
is%20in%20the%20title.%3C/p%3E%3Cstrong%3EBoiled%20Brocoli%3C/strong%3E%3Cbr%20/%3EApparently%20brocoli%20does%20not%20make%20for%20a%20good%20pesto.%20This%20tasted%20like%20brocoli%20I%20used%20to%20cook%20when%20I%20was%20eleven%20at%20home%2C%20which%20is%20to%20say%20I%20don%27t%20really%20remember%20it.%3C/p%3E
I want it to look like:
is in the title.
Boiled Broccoli
Apparently broccoli does not make for a good pesto. This tasted like broccoli I used to cook when I was eleven at home which is to say I don't really remember it.
Instead I'm getting:
is in the title.Boiled Broccoli
Apparently broccoli does not make for a good pesto. This tasted like broccoli I used to cook when I was eleven at home which is to say I don't really remember it.
Any ideas on how to properly decode this?
Thanks!
The start of the Paragraph tag is wrong. in your case,it starts with a end tag, like this < / p > (added space inside the tags for clarity). Also replace the strong tag with b. It should work now.
Separating the commands actually fixed this. So on separate lines I complete first the decode then the fromHTML.
Related
Suppose Html body is having below content
qwweeerrt
asssdfghjjkl
zxxcvbnmm
It is shown like below :
qwweeerrtasssdfghjjklzxxcvbnmm
when I used
webView.loadData()
and
qwweeerrt asssdfghjjkl zxxcvbnmm when I used
webView.loadDataWithBaseURL()
So empty lines between qwweeerrt , asssdfghjjkl and zxxcvbnmm are missing in webview.
Please suggest me how to show the content as it is.
HTML (not the WebView itself) hates blanks.
Please use the <br/> tag to add a carriage return.
Double it, for an empty line.
If you want to add some blank spaces, use for each space you want.
Or, as an alternative, include your text in a
<pre>
Your multiline text here
Second line
Third line
</pre>
structure.
The WebView only renders the HTML (but also CSS and JavaScript).
And it does a great job.
I recommend you to study some HTML, if you plan to use a WebView in your app.
A great (and historically proven to be accurate) learning source is found here.
Your 'content' has to be more formatted. Proper way to show it would be like.
<p>qwweeerrt</p>
<p>asssdfghjjkl</p>
<p>zxxcvbnmm</p>
See what the webView.loadData() shows now.
I have a slight issue. I wanna do something like we have here where we put in format markers such as this and this but I want it to appear in the edit text but not remove the marks for it. At the moment I'm achieving this with a preview button which displays an AlertDialog to show the previewed text.
I'm not sure which code to show as I have no idea how to do this at all. I also have no idea where to start on something like this. I've tried doing tons of research and it formats one word and then completely removes the markup/down for it.
Any help will be appreciated and I'm happy to supply any code whatsoever :)
I achieved this using a third-party library RichEditor and took the ones that I needed. It works really well for what I needed so I would recommend it for people to use.
It uses a webview for the EditText and then converts the text into a WYSIWYG formatting.
Folks,
In my social networking application, single-line messages come from various users. As the message comes in, I need to display them in our UI as a single line that shows the time, the user, and the message line. All 3 fields need to be colored differently.
I tried to use TextView but am running into a problem. As I need various colors, I thought of using SpannableString but the problem is that TextView.Append does not support SpannableString as a parameter.
The other thought I had was to build html style text as each line comes in.
I am wondering if I am overlooking something. Perhaps there is a better user control or a better way to achieve my objective.
Thank you in advance for your help.
Regards,
Peter
Use Html and with help of <font color><font/> tag, you can set single text with different color#
String result="<font color=color_code>First Textview</font> <font color=color_code>Second Textview</font><font color=color_code>Third TextView</font>";
textview.setText(Html.fromHtml(result));
You should use three different text fields, nest them in a table layout using columns, or a relative layout. That way they will automatically resize no matter what length.
You can also use the android:weight tag to control how much room each one takes up.
The reason is that usually its 1 label per field in data structure. As per MVC software design pattern.
In my application I need to add some string to a list and print them back. Problem is when I print them I can see the letters has inter change whithing the word.The word is in Arabic. (before 4.2 android doesnt support natively for Arabic).
What I tried was using several Arabic rendering classes such as fursi class and Arabi utility class. Nothing is helped me.
Here is the word ٣.. ما زاد على actually this part ٣.. should be the first it always goes to right as I have shown. Is there way to solve this thing. this is the one and only bug to hold the application to add to market :(
Oh, ouch! Arabic is worse than Hebrew in this aspect because Arabic has its own digits! Right!
I once had a similar problem on Windows, with symbols that weren't treated exactly as Hebrew but also not exactly as non-Hebrew. The only way I found to fix this was to split the string into two - print the problematic symbols (your 300) and then print the rest of the string.
I thought that with Unicode things has gotten better. I guess not always.
UPDATE: In a comment you said the translation of the string was 3.. . In Arabic, zero and a dot look very similar (which is why I confused a dot with a zero). Perhaps the person responsible of the input typed it wrong, not being fluent in Arabic, as well? 3.. doesn't make a lot of sense (3. does, and so does 300, but 3.. ?). Check the input, it might be wrong, and that can confuse the layout algorithm.
I can't technically understand the reason behind my action to correct above issue. However this is it . ` I reverse the word and separated letters by "+" and added to the list.It is amazing !
I'm working on an 'IDE' for Android - it could be useful for editing short scripts / making quick adjustments to files. At the moment I'm just using a simple EditText, but I am wanting to add several features, for example Line Numbering down the left hand side of the EditText and Code Highlighting.
Does anyone have any suggestions about how to approach this? For the code highlighting, I'm guessing I'll need to write my own subclass of EditText. For the line numbering, could I have a thin vertical TextView that has the same text size as the EditText??
Yes, I'm aware editing code on a mobile sized screen is painful.
Thanks!
The stock Email application uses an html view (android.webkit.WebView) to wrap even text emails in html. Perhaps rendering the code into html and displaying in a WebView would be a good way to get syntax highlighting.
For line numbering, the thin TextView beside the EditText seems reasonable. You might want to encapsulate it into your own View class that handles both subviews - and allows line numbers to be turned on and off (and perhaps does other good things like keep text size of both equal)
I think an ide for Android is a good idea. Would be nice to be able to code on an airplane without having to get the tray table involved =)