我使用 Eclipse ADT build:v21.1.0-569685,案例一是来自网站的示例代码,但它会导致错误“类型 new AdapterView.OnItemSelectedListener(){} 必须实现继承的抽象方法 AdapterView.OnItemSelectedListener.onNothingSelected(适配器视图)"
所以我必须使用案例二,但有时案例一还可以,发生了什么?谢谢!
案例一
private void InitSpinner(){
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item,
nameList.toArray(new String[nameList.size()]));
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerFolder.setAdapter(adapter1);
spinnerFolder.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(MainActivity.this,
"cw", 2000).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
}
案例二
private void InitSpinner(){
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item,
nameList.toArray(new String[nameList.size()]));
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerFolder.setAdapter(adapter1);
spinnerFolder.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
Toast.makeText(MainActivity.this,
"cw", 2000).show();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}