在下面的代碼,它們被實例化OnItemSelectedListener
裏面直接setOnItemSelectedListener()
方法,但它是一個接口下面的代碼是如何工作的精細解釋請人...OnItemSelectedListener是一個接口,但如何直接實例化?
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
}
});
}
外表匿名(內)類 – Blackbelt