我的应用程序中有一个微调器,我实现如下:
//Setup spinner spinner = (AppCompatSpinner) findViewById(R.id.toolbar_spinner); ArrayAdapteradapter = 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); } });
这适用于我的手机运行API级别19(4.4.2),但在Marshmallow,API级别23(6.0)上运行,从不调用onItemSelected.
我已尝试使用android.widget.Spinner和android.support.v7.widget.AppCompatSpinner同样的结果.
知道为什么吗?