Is there a way to use setOnClickListener with an Android Spinner?

后端 未结 2 1718
孤城傲影
孤城傲影 2020-12-16 23:58

The java.lang.RuntimeException is \"Don\'t call setOnClickListener for an AdapterView. You probably want setOnItemClickListener instead,\" but that is not correct. I am usin

2条回答
  •  失恋的感觉
    2020-12-17 00:35

    You can replicate the an onclick event using ontouch events

        this.spinner=(Spinner)findViewById(R.id.spinner);
        this.spinner.setClickable(false);
        this.spinner.setOnTouchListener(new View.OnTouchListener() {
    
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                Log.v(TAG, "spinner touch");
    
                //replicating a click
                if(event.getAction() == MotionEvent.ACTION_UP){
                    v.playSoundEffect(android.view.SoundEffectConstants.CLICK);
                }
                return true;
            }
        });
    

提交回复
热议问题