views:

1574

answers:

2

Is it be possible in the Android Hello, Spinner example to get the selected Spinner value with a listener, like for the other examples -- or do you need to subclass Spinner?

+2  A: 

Yes, you can register a listener via setOnItemSelectedListener(), as is demonstrated here.

CommonsWare
Thanks -- this worked too, and (I think) it makes the code easier to read.
Sam Dutton
+5  A: 

The Spinner should fire an "OnItemSelected" event when something is selected:

spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
    public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
        Object item = parent.getItemAtPosition(pos);
    }
    public void onNothingSelected(AdapterView<?> parent) {
    }
});
Erich Douglass
Thanks -- that worked, though I needed to add the void return type to the methods.
Sam Dutton