Spinner中有多个下拉列表项目点击

时间:2014-08-20 11:01:54

标签: android override android-spinner

当U点击下拉微调器列表中的所选项时,微调器不会调用onItemSelected方法。我需要做多个微调器的项目点击,所以我尝试创建自己的微调器。帮帮我做这件事。也许我需要@Override AdapterView中的某些方法。

1 个答案:

答案 0 :(得分:2)

试试这个

import android.content.Context;
import android.widget.Spinner;

public class MySpinner extends Spinner {

    public MySpinner(Context context) {
        super(context);
    }

    @Override
    public void setSelection(int position, boolean animate) {
        boolean sameSelected = position == getSelectedItemPosition();
        super.setSelection(position, animate);
        if (sameSelected) {
            // Spinner does not call the OnItemSelectedListener if the same item is selected, so do it manually now
            getOnItemSelectedListener().onItemSelected(this, getSelectedView(), position, getSelectedItemId());
        }
    }

    @Override
    public void setSelection(int position) {
        boolean sameSelected = position == getSelectedItemPosition();
        super.setSelection(position);
        if (sameSelected) {
            // Spinner does not call the OnItemSelectedListener if the same item is selected, so do it manually now
            getOnItemSelectedListener().onItemSelected(this, getSelectedView(), position, getSelectedItemId());
        }
    }
}