如何更改动态数据的语言

时间:2013-09-23 11:01:55

标签: android

我已经为语言选择创建了菜单。我正在通过JSON收集数据,因此这是运行时。现在我需要更改内容或数据的语言,以便我使用此代码。但它没有用。

     String languageToLoad  = "fa"; // your language
    Locale locale = new Locale(languageToLoad); 
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;
    getBaseContext().getResources().updateConfiguration(config, 
      getBaseContext().getResources().getDisplayMetrics());

请高手帮帮我。还有其他转换为语言的方式吗?还是任何图书馆?

1 个答案:

答案 0 :(得分:0)

    I think method you are using is correct. please check your language code.
    protected void language(String languageToLoad) {
            // TODO Auto-generated method stub
            Locale locale = new Locale(languageToLoad);   
            Locale.setDefault(locale); 
            Configuration config = new Configuration();  
            config.locale = locale;  
            getBaseContext().getResources().updateConfiguration(config,   
            getBaseContext().getResources().getDisplayMetrics());  
        }

   Be sure that strings file are exists in folder name appending by same language code.