Spinner onItemSelected没有调用

时间:2018-05-03 12:06:51

标签: java android

我在片段onCreate方法中使用以下代码。

spinner=(Spinner) rootView.findViewById(R.id.spinner1);
String [] values = {"Erkek","Kadın"};
ArrayAdapter<String> LTRadapter = new ArrayAdapter<String>(this.getActivity(), android.R.layout.simple_spinner_item, values);        LTRadapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
    spinner.setAdapter(LTRadapter);
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                    @Override
                    public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
                        Log.w("item","selected");

                       if (position == 0) {
                           spinnerTextView.setText("Erkek");
                       }else if(position == 1) {
                           spinnerTextView.setText("Kadın");
                       }
                    }

                    @Override
                    public void onNothingSelected(AdapterView<?> parentView) {
                        spinnerTextView.setText("");
                    }

                });

但onItemSelected方法没有调用。我该如何解决这个问题?

0 个答案:

没有答案