BlackBerry - Unicode text display

筅森魡賤 提交于 2019-12-02 07:41:07

Solution is to pass Unicode sequence as a char array:

char[] text = new char[] {'\u0627', '\u0644', '\u0639', 
    '\u0631', '\u0628', '\u064A', '\u0629'};
add(new LabelField(text));

So to display Unicode sequence kept in String, we need to parse this String into chars:

private char[] getUnicodeChars(String string) {
    char[] result = new char[] {};
    String[] charCodes = split(string, "\\");
    result = new char[charCodes.length];
    for (int i = 0; i < charCodes.length; i++) {
        result[i] = (char) Integer.parseInt(charCodes[i].substring(1), 16);
    }
    return result;
}

And somewhere in code:

String txt = "\u0627\u0644\u0639\u0631\u0628\u064A\u0629";
add(new LabelField(getUnicodeChars(txt)));

And there is no need to switch Locale. Of course Arabic font should be installed.

I'm displaying the Japanese Yen symbol on the device without having the device locale set to Japanese, simply by passing the string the unicode representation (as you do in your sample) and the j2me handles the rest. However, I'm not sure in such a situation the orientation will be right to left.

By default the device does not have the Arabic font, are you sure it is installed on the device? When you do:

Locale.get(Locale.LOCALE_ar, null)

Do you get back null or a locale value?

CORRECTION: The Yen symbol is not in unicode value but simply as clear text (I get it from the server). If you store the original string in Arabic in the resources (instead of the unicode), what does it show? Notice: putting the clear text in the code doesn't work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!