答案 0 :(得分:2)
我建议不要创建这样的方法并指定OnItemSelectedListener()
。只需在课堂上实现此功能
public class YourClass implements AdapterView.OnItemSelectedListener {}
并将this
分配给Spinner
,
或强>
尝试像这里一样匿名进行
mySpinner = (Spinner) findViewById(R.id.mySpinner);
mySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
int selectedPosition = arg2; //Here is your selected position
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
答案 1 :(得分:1)
您也可以将getCustomView(。,。,)用于此目的
public View getCustomView(int position, View convertView, ViewGroup parent) {
View row = inflater.inflate(R.layout.taxo_spinner_item, parent, false);
Pojo pojo = pojoList.get(position);
//.... blah blah
row.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context," position :"+position,short).show
}
});
return row;
}