I have an Android Spinner
and I'd like to get a callback when the user selects something from its popup dialog. It seems like setOnItemClickListener()
or setOnItemSelectedListener()
would be the right method to use, but neither get invoked when I select one of the items in the spinner.
Is there a correct way to do this?
UPDATE
Per commonsware's suggestion, I did the following, but my onItemSelected()
method is never being called:
final Spinner spinner = (Spinner) findViewById(R.id.spinner);
spinner.setAdapter( new ArrayAdapter<SettingValue>(getContext(), android.R.layout.simple_list_item_1, android.R.id.text1, setting.getSettingValues() ) );
spinner.setOnItemSelectedListener( new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Log.d("BOOGA");
final SettingValue settingValue = (SettingValue)parent.getSelectedItem();
final Editor edit = getContext().getSharedPreferences( PREFS_CONTEXT_NAME, Context.MODE_PRIVATE).edit();
edit.putString(setting.name(), settingValue.name());
edit.commit();
}
public void onNothingSelected(AdapterView<?> parent) {
// do nothing
}
});