[英]How to change the language of dynamically data
I have create menu for language choose. 我有用于语言选择的创建菜单。 I am gathering data by JSON so that is run-time. 我正在通过JSON收集数据,因此是运行时。 Now i need to change the language of contents or data so i am using this code. 现在,我需要更改内容或数据的语言,因此我正在使用此代码。 But it is not working. 但这是行不通的。
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());
Please expert help me. 请高手帮帮我。 is there other way for converting to language? 还有其他转换成语言的方法吗? or any library? 或任何图书馆?
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.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.