android – setOnItemClickListener不适用于Spinner

前端之家收集整理的这篇文章主要介绍了android – setOnItemClickListener不适用于Spinner前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
setOnItemClickListener不适用于Spinner.这是我的代码
supplier.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent,View view,int position,long id) {
                    // TODO Auto-generated method stub

                    String msupplier=supplier.getSelectedItem().toString();
                    Log.e("Selected item : ",msupplier);

                }
            });

解决方法

setOnItemClickListener将不适用于微调.尝试使用这种方法

setOnItemSelectedListener

更改你的代码如下:

supplier.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> arg0,View arg1,int arg2,long arg3) {
                // TODO Auto-generated method stub
                String msupplier=supplier.getSelectedItem().toString();

                Log.e("Selected item : ",msupplier);
}

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                // TODO Auto-generated method stub

            }
        });
原文链接:https://www.f2er.com/android/312599.html

猜你在找的Android相关文章