am new in android studio and I am trying to make my simple app weather info via yahoo weather service JSON data , i would like to make a different language display in my app
/***You need to create separate String file for both arabic and English***/
English
Values
String.xml
Arabic
Values-ar
String.xml
/**You can change the application language using the following code:**/
language = "en"; or language = "ar";
@Override
public void recreate()
{
if (android.os.Build.VERSION.SDK_INT >= 14)
{
super.recreate();
}
else
{
startActivity(getIntent());
finish();
}
}
private void updateLanguage(String language)
{
Locale locale = new Locale(language);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
SharedPreferences languagepref = getSharedPreferences("language",MODE_PRIVATE);
SharedPreferences.Editor editor = languagepref.edit();
editor.putString("languageToLoad",language);
editor.apply();
recreate();
}