0

This is my affected code

Object[] rooms = new Object[]{
    new OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            tmEditor.putInt("level", position);
        }

        public void onNothingSelected(AdapterView<?> parent) {
        }
    }, 
    new OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            tmEditor.putInt("amount", position);
        }

        public void onNothingSelected(AdapterView<?> parent) {
        }
    }
};

The problem is when I call it somewhere else with

((Spinner) widget).setOnItemClickListener((OnItemClickListener) rooms[1]);

Then I get a cast exception error

java.lang.ClassCastException: com.ssttevee.Loki$1$8 cannot be cast to android.widget.AdapterView$OnItemClickListener
4

1 回答 1

2

您不能投射AdapterView.OnItemSelectedListenerAdapterView.OnItemClickListener. 使用setOnItemSelectedListener或更改roomsAdapterView.OnItemClickListener.

于 2013-07-28T16:07:10.610 回答