0

我将我的微调器定义如下:

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 微调器时,不会发生此错误。有谁知道怎么了?

4

1 回答 1

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库包含它自己的AdapterView.OnItemSelectedListener,仔细检查你的听众扩展

org.holoeverywhere.widget.AdapterView.OnItemSelectedListener
于 2013-09-29T14:16:00.417 回答