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
2009-12-22 18:02:54
Thanks -- this worked too, and (I think) it makes the code easier to read.
Sam Dutton
2009-12-23 11:10:57
+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
2009-12-22 18:13:43
Thanks -- that worked, though I needed to add the void return type to the methods.
Sam Dutton
2009-12-23 10:43:57