在下面的代码中,他们OnItemSelectedListener
直接实例化了内部setOnItemSelectedListener()
方法,但它是一个接口,下面的代码如何正常工作,请向任何人解释...
public void addListenerOnSpinnerItemSelection() {
spinner1 = (Spinner) findViewById(R.id.spinner1);
spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,int position, long id) {
Toast.makeText(parent.getContext(), "OnItemSelected: " +parent.getItemAtPosition(position).toString(), Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
}