This question here is very helpful for me to start somehow. I have never tried localization of the application. So I am totally new here. But I am facing some problems still. I have list of languages like this;
<string-array name="languages">
<item>English</item>
<item>Finnish</item>
<item>French</item>
<item>German</item>
<item>Slovakian</item>
<item>Polish</item>
</string-array>
I want to set default to English when the application starts. And when the language is changed I want the same language to be run through the whole activities. In the link above, in method public void setLocale(String localeCode), what will be the localeCode in my case. And what will be the locale code here,Locale locale = new Locale(localeCode); . I know here might be Locale.setDefault(Locale.ENGLISH); . I have done so far like this, I know this is crap because it is not working what I am expecting. Could you please help me a right path. Thanks in advance
public class Base_Activity extends Activity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
final Spinner spinner = (Spinner) menu.getItem(0).getActionView()
.findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.languages, R.layout.spinner_row);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
// private String currentLanguage;
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// currentLanguage = spinner.getSelectedItem().toString();
Locale locale = null;
switch (arg2) {
case 0:
locale = new Locale("en_US");
break;
case 1:
locale = new Locale("fi");
break;
case 2:
locale = new Locale("fr");
break;
case 3:
locale = new Locale("de");
break;
case 4:
locale = new Locale("sk");
break;
case 5:
locale = new Locale("pl");
break;
default:
locale = new Locale("en_US");
break;
}
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
startActivity();
}
private void startActivity() {
overridePendingTransition(0, 0);
Log.i("DEBUG", "GATEWAY");
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
Locale.setDefault(Locale.ENGLISH);
}
});
return super.onCreateOptionsMenu(menu);
}}