“ getOnItemSelectedListener”方法不适用于微调器

时间:2019-10-08 15:49:16

标签: java android android-studio spinner android-spinner

        ArrayAdapter<CharSequence> adapter_height = ArrayAdapter.createFromResource(this,R.array.Height,android.R.layout.simple_spinner_item);
        adapter_height.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        height_spinner.setAdapter(adapter_height);

    height_spinner.getOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

微调器无法使用“ getOnItemSelectedListener”方法。请提出修改建议并解决我的问题 [错误如上所示] https://i.stack.imgur.com/jym1L.png

1 个答案:

答案 0 :(得分:0)

您必须使用setOnItemSelectedListener而不是getOnItemSelectedListener。如下所示。

height_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

      @Override
      public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {

    }

     @Override
     public void onNothingSelected(AdapterView<?> adapterView) {

    }
});