Spinner的OnItemSelectedListener不在选中状态时调用

时间:2018-07-09 11:27:19

标签: java android android-spinner

以下代码是我的Spinner初始化代码,但是当它被选中时,回调侦听器不会调用

 private void showSelectDialog(final List datas, final AdapterView.OnItemSelectedListener onItemClickListener) {
        if (EmptyUtil.isCollectionNotEmpty(datas) || datas.size() > 1) {
            final Spinner spinner = new Spinner(this);

            ArrayAdapter adapter = new ArrayAdapter(this, R.layout.spinner_item, datas);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinner.setAdapter(adapter);
            spinner.setDropDownHorizontalOffset(DeviceUtil.getDeviceWidth(this) / 2);
            spinner.setDropDownVerticalOffset(DeviceUtil.getDeviceHeight(this) / 2);
            spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                    ToastTool.showToast(PlaceanOrderActivity.this,"onItemSelected");
                    onItemClickListener.onItemSelected(adapterView,view,i,l);
                }

                @Override
                public void onNothingSelected(AdapterView<?> adapterView) {
                    onItemClickListener.onNothingSelected(adapterView);
                }
            });
            spinner.performClick();
        }
    }

谁对此问题有想法,请先谢谢!

0 个答案:

没有答案