我按如下方式定义我的微调器:
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" />
然而,这一行会引发错误:
sectionSpinner.setOnItemSelectedListener(new SectionListener());
错误为The method setOnItemSelectedListener(AdapterView.OnItemSelectedListener) in the type AdapterView<SpinnerAdapter> is not applicable for the arguments (MainActivity.SectionListener)
这是SectionListener类:
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
}
}
当我使用常规Android微调器时,不会发生此错误。谁知道什么是错的?
答案 0 :(得分:1)
尝试将SectionListener
类定义为
public class SectionListener implements AdapterView.OnItemSelectedListener
修改强>
您也可以尝试传递侦听器的匿名实例.-
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) {
}
});
编辑2
似乎 HoloEverywhere lib包含自己的AdapterView.OnItemSelectedListener
,仔细检查你是否是听众延伸
org.holoeverywhere.widget.AdapterView.OnItemSelectedListener