我编写了下面的类,让我从 Android Spinner 中获取枚举值。
有两行都getValue()
没有编译。
我该怎么做?
public class EnumSpinnerListener<T extends Enum> implements AdapterView.OnItemSelectedListener {
private String mValue = null;
public EnumSpinnerListener(AdapterView<?> adapterView) {
adapterView.setOnItemSelectedListener(this);
}
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
mValue = adapterView.getItemAtPosition(i).toString();
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
// do nothing
}
public T getValue() {
return Enum.valueOf(T.class, mValue); // cannot select from a type variable
return T.valueOf(mValue); // valueOf(java.lang.Class<T>, String) in enum cannot be applied to (java.lang.String)
}
}