2017-08-23 135 views
1

在我的android项目中,当我将语言切换到阿拉伯语时,通话记录页面不显示数据,但是当我切换到其他语言(如英语)可以正常显示,如何解决,请看下面的信息。为callLog适配器代码当我将语言切换到阿拉伯语,通话记录页面不显示数据

1.A部分如下:

holder.belong_area.setText("北京"); 

//显示归属地 
     if (callLog.getBelong_area() != null && !callLog.getBelong_area().equals("")) { 
      LogE.e("item","有归属地:"+callLog.getBelong_area()); 
      holder.belong_area.setVisibility(View.VISIBLE); 
      holder.belong_area.setText(callLog.getBelong_area()); 
     } else { 
      LogE.e("item","没有有归属地"); 
      holder.belong_area.setText(""); 
      holder.belong_area.setVisibility(View.GONE); 
     } 

2.It当我输入一个固定的值,例如如下仍然不显示数据

3.打印日志的日志如下:

10月8日至23日:07:13.241 17494-17494/com.allinone.callerid E /项目:有归属地:北京 08-23 10:07:13.607 17494-17494/com.allinone.callerid E/item: 有归属地:河北石家庄08-23 10:07:13.674 17494-17494/com.allinone.callerid E /项:有归属​​地:北京10月8日至23日:07:13.714 17494-17494/com.allinone.callerid E /项目:有归属地:湖北省,武汉市

4.Runtime截图:

阿拉伯语(错误),

enter image description here

english language(right)

enter image description here

回答

0

你应该有正确的字符集的系统。

您可以检查下面的代码来检测语言的charaterset。

public class CharsetDetectTest { 

    public static void main(String[] args) { 
     detectCharset("北京"); 
    } 

    public static void detectCharset(String originalStr) { 

     String[] charSet 
      = { "utf-8", "big5", "EUC-CN", "iso-8859-1", "gb2312" }; 

     for (int i = 0; i < charSet.length; i++) { 
      for (int j = 0; j < charSet.length; j++) { 
       try { 
        LogE.e("charaters", 
         "[" + charSet[i] + "==>" + charSet[j] + "] = " 
         + new String(originalStr.getBytes(charSet[i]), charSet[j])); 
       } catch (UnsupportedEncodingException e) { 
        e.printStackTrace(); 
       } 
      } 
     } 

    } 
} 

调试输出将是

[utf-8==>utf-8] = 北京 
[utf-8==>big5] = ��鈭� 
[utf-8==>EUC-CN] = ��浜� 
[utf-8==>iso-8859-1] = å京 
[utf-8==>gb2312] = ��浜� 
[big5==>utf-8] = �_�� 
[big5==>big5] = 北京 
[big5==>EUC-CN] = �_ㄊ 
[big5==>iso-8859-1] = ¥_¨Ê 
[big5==>gb2312] = �_ㄊ 
[EUC-CN==>utf-8] = ���� 
[EUC-CN==>big5] = 控儔 
[EUC-CN==>EUC-CN] = 北京 
[EUC-CN==>iso-8859-1] = ±±¾© 
[EUC-CN==>gb2312] = 北京 
[iso-8859-1==>utf-8] = ?? 
[iso-8859-1==>big5] = ?? 
[iso-8859-1==>EUC-CN] = ?? 
[iso-8859-1==>iso-8859-1] = ?? 
[iso-8859-1==>gb2312] = ?? 
[gb2312==>utf-8] = ���� 
[gb2312==>big5] = 控儔 
[gb2312==>EUC-CN] = 北京 
[gb2312==>iso-8859-1] = ±±¾© 
[gb2312==>gb2312] = 北京 

然后,使用正确的字符集之一。

holder.belong_area.setText(new String("北京".getBytes("utf-8"), "utf-8")); 

holder.belong_area.setText(new String("北京".getBytes("utf-8")); 

您可以查看中国系统字符site

最好的问候,

+0

这是我的荣幸。如果你认为这对你有帮助,你可以为我做点赞成^^。 – tommybee