I define my spinner as follows:
import org.holoeverywhere.widget.Spinner;
private static org.holoeverywhere.widget.Spinner sectionSpinner;
sectionSpinner = (org.holoeverywhere.widget.Spinner)findViewById(R.id.sectionSpinner);
<org.holoeverywhere.widget.Spinner
android:id="@+id/sectionSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/circleSeek"
android:layout_alignParentBottom="true"
android:gravity="center" />
This line, however, throws an error:
sectionSpinner.setOnItemSelectedListener(new SectionListener());
The error is The method setOnItemSelectedListener(AdapterView.OnItemSelectedListener) in the type AdapterView<SpinnerAdapter> is not applicable for the arguments (MainActivity.SectionListener)
Here is the SectionListener class:
public class SectionListener implements OnItemSelectedListener {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
if (userSelected) {
resetAction();
setTimeText(sectionTimes[pos], sectionTimes[pos]);
currentSection = pos + 1;
setSectionText(currentSection);
currentStartTime = sectionTimes[pos];
currentTime = currentStartTime;
setSeekBarProgress(currentTime, currentStartTime);
}
else {
userSelected = true;
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// Not needed
}
}
This error does not occur when I use the regular Android spinner. Anyone know what's wrong?
Try defining SectionListener
class as
public class SectionListener implements AdapterView.OnItemSelectedListener
EDIT
You could also try passing an anonymous instance of the listener.-
sectionSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, android.view.View v, int pos, long id) {
if (userSelected) {
resetAction();
setTimeText(sectionTimes[pos], sectionTimes[pos]);
currentSection = pos + 1;
setSectionText(currentSection);
currentStartTime = sectionTimes[pos];
currentTime = currentStartTime;
setSeekBarProgress(currentTime, currentStartTime);
} else {
userSelected = true;
}
}
public void onNothingSelected(AdapterView<?> parent) {
}
});
EDIT 2
It seems that HoloEverywhere lib includes its own AdapterView.OnItemSelectedListener
, double check you're listener extends
org.holoeverywhere.widget.AdapterView.OnItemSelectedListener