Hi guys,
I have a spinner successfully working but I am trying to use the
spinner.setSelection method to "remember" the previous spinner value
when the activity is reloaded.
Outside of setOnItemSelectedListener, is there a function of the
spinner that can give me the selected index?
The following code is my function code to both setup the spinner and
then my attempt to set the spinner with the index previously selected:
private void setSpinner(int spinnerID){
final Spinner spinner =
(Spinner)findViewById(R.id.Spinner_gender);
int spinner_value;
spinner.setOnItemSelectedListener(
new AdapterView.OnItemSelectedListener() {
public void
onItemSelected(AdapterView<?> parent, View
itemSelected, int selectedItemPosition, long selected){
spinner_value =
selectedItemPosition;
Editor editor =
mGameSettings.edit();
editor.putLong(GAME_PREFERENCES_GENDER,
selectedItemPosition);
editor.commit();
Toast.makeText(QuizSettingsActivity.this, "selected:
"+GAME_PREFERENCES_GENDER+"("+ spinner_value +")",
Toast.LENGTH_SHORT).show();
}
@Override
public void
onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated
method stub
}
}
);
ArrayAdapter<?> adapter =
ArrayAdapter.createFromResource(this,
spinnerID, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
if( mGameSettings.contains(GAME_PREFERENCES_GENDER) ){
spinner.setSelection(spinner_value);
}
}
All I am trying to do here is use spinner_value to remember the
selected index so I can set the spinner to that index.
However, the spinner_value is never holding the desired value at
spinner.setSelection(spinner_value); in the last lines of code
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en