我有一个 ListView,我想创建一个 OnItemSelectedListner,我在代码中这样做,我称之为 mylistener。为什么 list.setOnItemSelectedListener 不接受 mylistener?
感谢您的帮助
ListView list = (ListView)findViewById(android.R.id.list);
ArrayAdapter<String> adapter = new ArrayAdapter<String> (this,android.R.layout.simple_list_item_1,array);
list.setAdapter(adapter);
list.setOnItemSelectedListener(mlistener);
AdapterView.OnItemSelectedListener mlistener = new AdapterView.OnItemSelectedListener(){
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
Toast.makeText(getApplicationContext(),"selezionato", Toast.LENGTH_LONG).show();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
};