At this moment I am creating a small Android app, as a hobby.
It is not something serious: it makes a query from an sqlite database, and displays the results in a listview element. If you click on an item in the list, it makes another query with the content of the element, and displays the new results. (e.g. You tap on a city, it displays the restaurants in the city. If you tap on the city, it displays the foods available)
Now my problem is that most of these texts contain some special characters (like Ľ - u013D) that are not displayed correctly. And since they are not displayed correctly, I am unable to make further queries with them also.
I have tried many ways, mainly what I saw on this forum, however I am too noob for that unfortunately. This is what I have:
//DataBaseHandler is just a custom class creating and executing SQL queries, nothing special. It extends to SQLiteOpenHelper
DataBaseHandler db=new DataBaseHandler(this);
//getStations returns a List<String> object with the required items, contains raw strings
ArrayList<String> StationList=(ArrayList<String>) db.getStations(i.getStringExtra("jaratszam"));
db.close();
lv=(ListView) findViewById(R.id.listStation);
ArrayAdapter<String> aa=new ArrayAdapter<String>(this, R.layout.tv, StationList);
lv.setAdapter(aa);
I have tried to modify the strings I got back with Html.fromHtml, also CharSequence[], but none helped (I guess i did not use them correctly). I have modified my database also, I have changed the special characters to html codes, like
�E1;
Could you please enlighten me what should I do exactly?
Thanks in advance.
You probably need to user the correct character set for your String, although UTF-8 (which is the default) should support most foreign and special characters. Here's how you create a new String with a custom charset from an old String:
String newString = new String(oldString.getBytes(), Charset.YOUR_CHARSET_HERE);
Now my problem is that most of these texts contain some special
characters (like Ľ - u013D) that are not displayed correctly.
Try Encoding your string before putting it in database and decode it before using it in your application.
Related
so I'm just getting started in Java/Android Development and currently working on an assignment which I've gotten to work the way I want it to except for one part. So in this app you are supposed to be able to add "sandwiches" to an order, and then have your order presented below. I have the user adding sandwiches through a ListView with clickable options, as that's the idea, but then when presenting the order I want to store and present all the clicks, i.e. all the mackor that "have been ordered" in the TextView below the ListView, however I only manage to store and present one selection at a time, and when another one is clicked, the previous one is replaced. I've been trying to read up on this and I'm thinking a for or do-while loop should probably be used for this? However I did try a couple different versions of that without getting it to work, so here I am.
So tl;dr everything is working the way I want it to except for the selections just "replacing" eachother instead of adding up - how do I add a String/object to the ArrayList everytime a user selects an option in the ListView instead of having it just switching these? I was advised to use ArrayList to store these selections, but right now it's not of much use as it's just holding one at a time lol. I'm sure there are a lot of other things not done ideally in this program as well but yeah. Any advice on how to get this to work properly would be much appreciated! I figured my XML shoulnd't be necessary to include as that's not the issue but I gladly will if needed.
How to load two texts like in the picture? That is, I have two texts stored in the database, one in English, the other in Russian. I am using a php script to load from the database. I also use Retrofit. How to take a string from two texts in turn and load it into a textview
this is what i want to achieve
UPDATE: I have two lyrics, one in English, the other in Russian. I need to pull out one line from the English text, and immediately below it the line from the Russian
db
I'm using Sqlite with Android (Java).
I have a database that contains texts with hebrew punctuation.
My problem is that when I'm doing a SELECT for certain value (without punctuation) I don't get all the results as I guess the DB is not ignoring the records that are punctuated and treating the punctuation as a normal characters.
After doing a search, I found some answers which says I should register a collation for it (sqlite3_create_collation).
As I've never used collations, I would like if some one will give me a hint on how to register it and use it to get the correct full result as I want.
For example:
SELECT * FROM sometable WHERE punctuated_field LIKE '%re%'
I would like to get both the following:
dream
drém
Currently I'm getting just:
dream
I read this relevant answer but didn't managed to understand how to implement it within my query or the Java code.
I would be happy to have someone writing the full query required for me to write within my code.
Thanks in advance!
The Android API does not allow registering custom collations.
You have to make do with the built-in collations, or with Android's LOCALIZED and UNICODE collations.
Since the Android sqlite API doesn't expose anything to set up custom collations, you'll have to figure some other way to solve the problem.
One is to add another column where you have the strings normalized i.e. accent marks ("punctuation" as you like) removed. Then do your LIKE matching on this normalized column and use the original column for display purposes. The cost of this is larger data size and some extra code when inserting into the database.
I've described one such normalization approach in here:
How to ignore accent in SQLite query (Android) - I have no idea how well that works with Hebrew chars though.
My app is English only but some of the data that I am dynamically retrieving and displaying is from a different language (Eg: Korean). I am doing this before adding the string item to a list view:
test = new String(item.name.getBytes("UTF-8"));
When I use the Eclipse debugger to check the test string, I am able to view the string with the appropriate language characters but when I display the listview on the emulator, it turns into garbage.
I've read that Android automatically supports languages like Japanese, Telugu etc so I am assuming that I am doing something wrong here. Can anyone help? Thanks!
Why the hell are you doing this? You have a string, encode it in UTF-8 and THEN decode it with the platforms default encoding - this obviously will fail if the default encoding is anything but UTF-8.
Obvious fix: test = item.name.
Also correct but rather useless: test = new String(item.name.getBytes("UTF-8"), "UTF-8");
I'm doing a standard SQL query in Android:
String selection = "SELECT phraseA, phraseB FROM TableXYZ";
Cursor c1;
c1 = myDbHelper.myDataBase.rawQuery(selection,null);
c1.moveToNext();
while(!c1.isLast()){
toplist.add("Phrase: "+c1.getString(0)+" "+c1.getString(1);
c1.moveToNext();
}
c1.close();
The table is very small and the number of returned stirngs is less than 40. Toplist is an ArrayList. It is put into a ListView.To the best of my knowledge this should show me 40ish strings. Now, what happens is the strings are shown but then another load of empty ListView fields come up. I have no idea how. I thought my iteration might be wrong, but I can't find fault with it.
Aren't you skipping the last result always? I think you need: while(!c1.isAfterLast()) to keep from skipping the last item.
Also this line has a syntax error:
toplist.add("Phrase: "+c1.getString(0)+" "+c1.getString(1);
you are missing a ")" character.
As for your question, you aren't showing enough code to really see what the problem is. Are you sure you aren't adding any empty values to the ArrayList at some other point in your code? All you are showing here is how you are populating an array list, not how you are populating a ListView. Show your ListView code.
It would also be fairly trivial to attach the debugger to see what your ArrayList contains after this step, to see if the error is in this part of your code or somewhere else. Or for that matter even printing the ArrayList size to LogCat would help in debugging this.