Thanks for responding. I have the following code:
final Spinner spinner = (Spinner)findViewById(R.id.Spinner_gender);
spinner.setOnItemSelectedListener(
new AdapterView.OnItemSelectedListener() {
public void
onItemSelected(AdapterView<?> parent, View
itemSelected, int selectedItemPosition, long selected){
Editor editor =
mGameSettings.edit();
editor.putLong(GAME_PREFERENCES_GENDER,
selectedItemPosition);
editor.commit();
}
@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) ){
Toast.makeText(QuizSettingsActivity.this,
"Detected(again): " +
spinner.getSelectedItemPosition(), Toast.LENGTH_SHORT).show();
spinner.setSelection( spinner.getSelectedItemPosition()
);
}
Towards the end, I am checking that a sharedPreference value is set
and simply printing the selectedIndex in my Toast.
But, the very next line I am using the same function call but my
spinner does not set to the previously selected value when the
activity is re-loaded.
However, if I simply give spinner.selection a static argument, e:g 2,
it works fine upon re-loading the activity.
I don't know why it won't work ... please help!
On Nov 10, 5:47 pm, TreKing <[email protected]> wrote:
> On Tue, Nov 9, 2010 at 5:58 PM, sisko <[email protected]> wrote:
> > Please enlighten me as to why the getSelectedItemPosition() function
> > displays the currently selected value in my toast but
> > as I try using it in my seSelection call, my spinner never sets to the
> > value confirmed in my above toast ?
>
> This doesn't make sense. If getSelectedItemPosition returns the correct
> selected value, then calling setSelection() with that value will have no
> effect and the spinner will not change because you're already on the correct
> item, so how is it that the spinner "never sets to the value confirmed"?
>
> I think you need to elaborate.
>
> -------------------------------------------------------------------------------------------------
> TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
> transit tracking app for Android-powered devices
--
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