In my application I have a option of language selection.
There are three languages: English, German & Spanish. When I select an option, the entire application la
You just add the value folder according to the language.
For example, I have added 3 languages: English, Arabic and Hindi.
In res
folder create values-ar
for arabic and values-hi
for hindi to hold all strings used in application.
Now I have a listview of languages. So when the user clicks on one of the language, the language of application will be changed and the phone language will remain same.
Here is the code ..
listview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
String language = ((TextView) view).getText().toString();
if (language.equals("English")) {
Locale locale = new Locale("en");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources()
.updateConfiguration(
config,
getBaseContext().getResources()
.getDisplayMetrics());
Toast.makeText(ChangeLanguage.this, "Locale in English",
Toast.LENGTH_LONG).show();
} else if (language.equals("Arabic")) {
Locale locale = new Locale("ar");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources()
.updateConfiguration(
config,
getBaseContext().getResources()
.getDisplayMetrics());
Toast.makeText(ChangeLanguage.this, "Locale in Arabic",
Toast.LENGTH_LONG).show();
}else if (language.equals("Hindi")) {
Locale locale = new Locale("hi");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources()
.updateConfiguration(
config,
getBaseContext().getResources()
.getDisplayMetrics());
Toast.makeText(ChangeLanguage.this, "Locale in Hindi",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(ChangeLanguage.this,
"Locale in not changed!", Toast.LENGTH_LONG).show();
}
/*
* Toast.makeText(getApplicationContext(), language,
* Toast.LENGTH_SHORT) .show();
*/
GetterSetter.getInstance().setLanguage(changelanguage);
startActivity(new Intent(ChangeLanguage.this,
MainSettings.class));
main.tabhost.setCurrentTab(3);
}
});