0

我们在我们的Android应用程序中共使用6种语言,用户可以从中选择。我们以编程方式设置区域设置。语言为 英文,印地文,泰米尔语,Telegu,卡纳达语,马拉雅拉姆语,马拉地语。在Android应用程序中更改语言时的应用程序状态更改

使用下面的代码我们更改应用程序的语言。

locale = new Locale(lang); 
Locale.setDefault(locale); 
Configuration conf = new Configuration(config); 
conf.locale = locale; 

getApplicationContext().getResources().updateConfiguration(conf,getBaseContext().getResources().getDisplayMetrics()); 

当我们改变印地文和英文应用之间的语言能够从共享偏好获取数据,但对于其他语言,它在同一查询返回null。请帮助

更新1:以下是由于您使用的字符串值,以获得从sharedpreferences R.string.shared_prefs_key的数据,这就是为什么在问题发生时从共享偏好

SharedPreferences sharedPrefs = context.getSharedPreferences(context.getString(R.string.shared_prefs_key), Context.MODE_PRIVATE); 
    String value = sharedPrefs.getString(key, null); 
+0

'它返回null相同query.'表演工作 –

回答

0

检索数据的代码,因为将键在不同的语言字符串中改变。而且由于数据是在不同的密钥中存储的,因此其他语言密钥将为空。

变化是在一个恒定值象下面这样:

SharedPreferences sharedPrefs = context.getSharedPreferences("<your key>", Context.MODE_PRIVATE);