2

Is it possible to sort the languages other than English at the runtime? I have something like this so far:

String bug_arr={"Инсталиране на безжична връзка","Инсталиране на безжична връзка","Инструкции за безопасност"};
String arabic_arr={"رحمن","مدينة"};
String en_arr={"Hello","Air"};

Can this be sorted - Arrays.sort(bug_arr);?

Unfortunately when i tried this, I got a message saying 'Java/Eclipse: Some characters cannot be mapped using “Cp1252″ character encoding'.

Anyone have any idea ?

Sajal Dutta
  • 18,272
  • 11
  • 52
  • 74
Aada
  • 1,591
  • 7
  • 30
  • 57

3 Answers3

3

Sort using Collator. Like-

Collator collator = Collator.getInstance(Locale.JAPAN);
Collections.sort(phraseList, collator);

Example-

String arabic_arr[] = {"رحمن","مدينة"};
Collator arabicCollator = Collator.getInstance(new Locale("ar"));
Collections.sort(Arrays.asList(arabic_arr), arabicCollator);

EDIT:

For your encoding related problem, you might want to see this answer-

How to use Special Chars in Java/Eclipse

Community
  • 1
  • 1
Sajal Dutta
  • 18,272
  • 11
  • 52
  • 74
1

It sounds like what is happening is that Eclipse is trying to figure out how to map those strings into a language that it can understand, but it is failing because cp1252 does not support unicode strings like the ones you mentioned.

If this is the case, the solution is to save your files as UTF-8. In order to do this, go to File -> Properties. Select Resource on the left and go down to "Text Files Encoding". Set this to be UTF-8.

Jonathan
  • 3,369
  • 4
  • 22
  • 27
0

So far am concerned it should work. But just update ADT and use API higher then 7(may be from gingerbread).. you can directly hard code it in your java program or can use it as a resource array.

setText("bengali language and arabic language");

above method just work for me for my native bangla language and also worked with arabic language. May be all you need is to update.

androCoder-BD
  • 498
  • 7
  • 13
  • Hi, Ya setText(...) works just fine for the languages i tried. But yes, i guess you are right, i should try with API higher than 7. Let me try and get back. – Aada Jul 21 '13 at 05:24