I have a Periodic table of elements app for android that stores most of it's data in string arrays. I am now trying to use an sqlite database instead of the arrays but am having a small problem. If I type 'android:text="¹"' directly into a TextView it will display a superscript 1(like this-> ¹), but if I store '¹' as text in a sqlite database and then use a cursor to populate that same TextView, instead of the superscript 1 being displayed I just see "¹" exactly as I typed it. How can I get the TextView to display special characters when being populated by a sqlite database? I have been struggling for a while and am stumped so any suggestions would be appreciated. Thanks!
Use the Java Unicode string notation for each special character when inserting them into your database.
For '¹', that would be: \u00b9.
Alternatively, to parse HTML tags and character entities like ¹ in a TextView, then you can probably wrap the String in a call to Html.fromHtml() before calling setText().
Related
I have a problem when executing select query in android with sqlite database. In database there is a field based on sinhala characters. I populate the database using DB browser in UTF-8 encoding. I used SQLiteAssetHelper to access database in assets folder. when i try to use select query and display in android textview the data in field based on sinhala outputs strange characters like විද්â€.
I try to change the font in textview and try to change the encoding by using System.setProperty( sinhala_word,"UTF-8" ).
As example when try to set word
රහිත
in android text view it shows like
රහිà¶
this is how my database looks like:
This is how text appears in text view:
In Android, I have an application that handles multiple rich format text fields. I get the description of the text from an xml and create it as an spannable string builder, adding each run and styling it.
Is there a way to store this on sqlite that doesn't imply storing the whole XML describing the paragraph?
I know it can be done in iOS but I haven't found a way for Android.
Thanks in advance for any answers or tips.
Is there a way to store this on sqlite that doesn't imply storing the whole XML describing the paragraph?
I do not know what "the whole XML describing the paragraph" is. You can:
Use Html.toHtml() to generate HTML from a Spannable, or
Roll your own code to convert a Spannable into something that can be stored as a string or byte array
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.
I ma trying to insert some data into the database. The data contains single quotes. I tried to escape them with back slash like "Scr\'anton" while inserting the data:
INSERT INTO employee VALUES(4,'Jim','Halpert','Assistant Regional Manager','Manage',2,'Scr\'anton','570-222-2121','570-999-1212','jim#dundermifflin.com','halpert.jpg')
I tired to use DatabaseUtils.sqlEscapeString() with no effect at all. What is the best way to escape characters?
use double single quotes 'Scr''anton'
Take a look at StringEscapeUtils (details here), found in the Lang component of Apache Commons. You can easily download this and add it to your project.
You can use the method update
http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html