I am trying to change the Language by pressing a button in the menubar, but i want it to switch between Norwegian and English Language. So if the the locale.toString() is "no" i'll switch to "en" and vise versa.
My problem is that i only get it to switch once and not change back if i press the button.
This is the Method used:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.Language:
TextView textview = (TextView) findViewById(R.id.resultat);
locale = getResources().getConfiguration().locale;
switch(locale.toString()){
case LOCALE_NORWEGIAN:
textview.append("EN ACTIVATION");
locale = new Locale("en");
break;
case LOCALE_ENGLISH:
textview.append("NOR ACTIVATION");
locale = new Locale("nor");
break;
default:
textview.append("DEFAULT "+locale.toString());
}
Resources res = this.getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.setLocale(locale);
res.updateConfiguration(conf,dm);
startActivity(new Intent(this,Game.class));
finish();
return true;
case R.id.Rules:
return true;
default:
return super.onOptionsItemSelected(item);
}
}
This is how it looks, I want the Language to change when i press the button With the flagg on it. But when i press it more than once the Language won't change