I've got a TextView in my app to put my data obtained from scraping.
the data is some chinese words (unicode), the view shows the unicode instead of these chinese words.
I've find out the problem is caused by "\uxxxx" and "\uxxxx". The system return the value of "\uxxxx".
The chinese words can be show if I hard code the string pass into it, for example
Title.setText("\u4F60\u597D\u55CE");
\\ the chinese words can show properly as "你好嗎"
Title.setText("\\u4F60\\u597D\\u55CE");
\\ the words show as "\u4F60\u597D\u55CE"
I try to compare the different:
Log.i("setTitle", String.valueOf(Title.equals("\u4F60\u597D\u55CE")));
//returned false but should be true
Log.i("setTitle", String.valueOf(Title.equals("\\u4F60\\u597D\\u55CE")));
//returned true but should be false
I've tried
Title.replace("\\\\u","\\u");
Title.replace("\\\\","\\");
these all provides the same result in my comparison code
I've even tried
Title.replace("\\","").replace("u", "\\u")
I still cannot get the result I want.
Just want to ask is there any way I can show chinese character with unicode in TextView.setText()?
Just replace all \\u with \u before setting it to the Textview and that should work.
Related
I am wondering why Android doesn't support this.
To explain my problem. I am working on an accessibility feature for an Android app.
I have a TextView that displays a number value like 123456.
If I use TalkBack, it will always read just this number value.
What I want it to give this value a context so that TalkBack would read something like: "Number value 123456" I am not able to do that as contentDescription just overrides the text value and hint attribute is read after the value like: "123456 Number value".
Is there an alternative for this? Let me also say that the app is not using a separate TextView which would say "Number value" that TalkBack could read.
The solution I did was to use
var number = 123456
textView.contentDescription = "Number value ${number}"
I am making a note application and want the user to be able to edit in rich text.
The user writes the note, then it gets converted into html and saved into a database.
This way when it is retrieved from the database, it does not lose its rich text.
Yet I am having a problem, if the user adds a color to their text and saves the note it converts it to html like this
"<p><font color=#0000ff>user text</font></p>"
when retrieved from the database no text color shows up. this is because android saves the html wrong. In order for android to get color from html the letters need to be capitalized like this
"<p><font color=#0000FF>user text</font></p>"
This confuses me because if android can only read it in caos why doesn't it convert it in that way.
How do I get it so when this code runs
//--save to string--//
Editable e = noteContent.getText();
String s2 = Html.toHtml(e);
Spanned s3 = Html.fromHtml(s2);
classes.setText(s3);
to save the text color to the caps. so when it is retrieved form the database the text color shows up.
Thanks,
Jordan
Make sure your RGB value is CAPITALIZED.
Try to use:
Html.fromHtml("<![CDATA[<font color='#145A14'>text</font>]]>");
Hope this help!
I have an EditText called content. Inside it is some formatted text. I then want to switch between seeing the formatted text and the html by doing :
if(!showHtml)
content.setText(Html.fromHtml(content.getText().toString()), BufferType.SPANNABLE);
else
content.setText(Html.toHtml(content.getText()));
If the formatted text is "test test", the html comes out as <p>test <b>test </b></p> which is fine, but when going back, the formatting is lost and I get "test test".
If the formatted text is "test test", the html comes out as <p><b>test</b> test</p>, which is correct once again. However, the text obtained when going back is "test test".
So what it looks like is that the formatting of the first word is applied to the rest of the text (I've tested it on longer strings).
Has anyone encountered this before, and how could I go about solving this?
Edit 1 It seems that with EditText.setText(), it automatically uses the Editable flag and completely ignores my request for a Spannable. Could this be where the problem is coming from?
I was being a fool. I had completely forgotten that I had a TextWatcher that modified the styles that were applied. All I needed to do was set a flag telling it not to modify the styles if it was after converting from html.
can any one know about how to add/insert emotions/smiles to text(which ever i typed in my edit text for my notes). i have little confusion about if i want to add these smiles of type .png in to edit text type of string, is it possible? and also i have to save these input into sqlite database. normally i know to store string data taken from edit text.
but along with that text i want to also add smiles symbols where ever my cursor placed and to be store in sqlite data base. and get it back to read.
so guys any ideas, most welcome!
Try to use java (i.e. android) spannable method to implement smiley (i.e.) images for that. You will surely get it, search in google for "how to add images/smiley with java spannable method in android?" you will get good idea.
Reading your question the first thing I can think of is Mapping each image to a sequence of letters, for example :) is smiley.png etc. Now your database also has these smaller representation However while reading from the database you can convert those special character sequences to appropriate image.
For simplicity in seraching those Strings You can wrap them in some less used characters i.e. [ or { or <.
I am trying to create a database for an android app including, in part, non-English words which require underlines and accents for proper spelling. I set my encoding for this package to utf-8, which allowed the accented characters to store and display properly. However, I cannot seem to get a single character underlined. It displays an empty box for an unrecognized character.
An example of my database helper to create the sqlite is as follows:
cv.put(ENGLISH, "to be alive");
cv.put(NATIVE, "okch_á_a or okchaha");
cv.put(PART_OF_SPEECH, "verb");
cv.put(AUDIO, "alive");
cv.put(VIDEO, "none");
cv.put(IMAGE_DEFAULT, "none");
cv.put(IMAGE_OPTIONAL, "none");
cv.put(IMAGE_TO_USE, "none");
db.insert("words", ENGLISH, cv);
That
_ a _
is the best I can come up with so far, but the a should actually be an underlined character.
I tried html tags like u and /u:
<u>a</u>
since that works with string arrays, but it displays as:
<u>a</u>
(the html is never interpreted).
I tried using:
"\u0332"
as explained at http://www.fileformat.info/info/unicode/char/332/index.htm , but that, too, is never interpreted, so it displays as:
a\u0332
I also tried:
& # 818 ;
and:
& # x332 ;
in a similar manner, with similar lack of results.
Any ideas?
You can store your string in Html format and call .setText(Html.fromHtml(somestring)) from the textview were you want to display it.