请有人在附加的微调器代码中告诉我我的错误。它崩溃了应用程序
String arr[] = {"Maths", "Biology"};
ArrayAdapter a = new ArrayAdapter(this,android.R.layout.simple_spinner_item, arr);
Spinner spin = (Spinner) findViewById(R.id.spin1);
spin.setOnItemSelectedListener((AdapterView.OnItemSelectedListener) this);
spin.setAdapter(a);
答案 0 :(得分:1)
您无法为AdapterView.OnItemSelectedListener
转换活动spin.setAdapter(a);
spin.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
//Get position and the related item from here
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
//Another interface callback
}
});