I wanted the spinner to select from the following 3 countries but im only able to access the 2nd and 3rd option. When i select the first option the spinner doesn't work.
String[] countries = { "INDIA","AUSTRALIA","ENGLAND"};
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
if (!mSpinnerInitialized) {
mSpinnerInitialized = true;
return;
}
if(spinner.getSelectedItem().toString().equals("INDIA")){
LocaleManager.setNewLocale(LoginActivity.this, "en");
restart();
}else if(spinner.getSelectedItem().toString().equals("AUSTRALIA")){
LocaleManager.setNewLocale(LoginActivity.this, "si");
restart();
}else if(spinner.getSelectedItem().toString().equals("ENGLAND")){
LocaleManager.setNewLocale(LoginActivity.this, "ta");
restart();
}
Toast.makeText(LoginActivity.this, spinner.getSelectedItem().toString(), Toast.LENGTH_LONG).show();
}
Spinner Initialization
ArrayAdapter aa = new ArrayAdapter(this,R.layout.languagespinner,countries);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(aa);
The spinner text named INDIA should be accessed but I cannot do it unfortunately.
EDIT
It might be because of the mSpinnerInitialized but if i remove that , the activity is restarted in an endless loop
Change your code to:
in
onCreatedo this:To change your language use this code:
And in your Spinner Class use this method to change the language:
And for restart use this method: