1

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

&#00E1;

Could you please enlighten me what should I do exactly?

Thanks in advance.

4

2 回答 2

2

您可能需要为您的字符串使用正确的字符集,尽管 UTF-8(这是默认值)应该支持大多数外来字符和特殊字符。以下是使用旧字符串的自定义字符集创建新字符串的方法:

String newString = new String(oldString.getBytes(), Charset.YOUR_CHARSET_HERE);
于 2013-05-11T17:26:14.657 回答
1

现在我的问题是这些文本中的大多数都包含一些无法正确显示的特殊字符(如 Ľ - u013D)。

尝试在将字符串放入数据库之前对其进行编码,并在将其用于应用程序之前对其进行解码。

于 2013-05-11T18:34:46.443 回答