Spinner onItemSelected not called with marshmallows

In my application there is a spinner that I implement like this:

   //Setup spinner
    spinner = (AppCompatSpinner) findViewById(R.id.toolbar_spinner);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.sections, R.layout.spinner_item);
    adapter.setDropDownViewResource(R.layout.spinner_list_item);
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            mViewPager.setCurrentItem(position);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            mViewPager.setCurrentItem(0);
        }
    });

This works great with my phone running on API level 19 (4.4.2) but running on Marshmallow, API level 23 (6.0), onItemSelected is never called.

I tried with both android.widget.Spinner and android.support.v7.widget.AppCompatSpinner with the same result.

Any ideas why?

+4
source share
1 answer

Android Spinner: onItemSelected listener not called when selecting the same item

Just create a CustomSpinner;

Thus, the problem is solved on Marshmallow;

0
source

Source: https://habr.com/ru/post/1619124/


All Articles