我按下按钮打开一个微调器。 现在,当我选择一个微调器项时,我的setOnItemSelectedListener不会被触发。只有微调器在选择项目时才会关闭。
代码如下: -
holder.button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
final Spinner spinner = new Spinner(activity);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(activity,"Selected",Toast.LENGTH_LONG).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
final CustomSpinnerAdapter adapter = new CustomSpinnerAdapter(
activity);
spinner.setAdapter(adapter);
spinner.performClick();
}
});
答案 0 :(得分:0)
我认为问题在行
final Spinner spinner = new Spinner(activity);
我们的微调器具有修饰符“final”,尝试将我们的微调器声明为一个字段。 例如:
holder.button.setOnClickListener(new OnClickListener() {
Spinner spinner;
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
spinner = new Spinner(activity);
...
}
});