Setting a spinner onClickListener() in Android

后端 未结 7 777
不思量自难忘°
不思量自难忘° 2020-11-29 03:43

I\'m trying to get an onClickListener to fire on a Spinner, but I get the following error:

Java.lang.RuntimeException is \"Don\'t call setOnClickListe

7条回答
  •  难免孤独
    2020-11-29 04:01

    Whenever you have to perform some action on the click of the Spinner in Android, use the following method.

    mspUserState.setOnTouchListener(new OnTouchListener() {
    
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                doWhatIsRequired();
            }
            return false;
        }
    });
    

    One thing to keep in mind is always to return False while using the above method. If you will return True then the dropdown items of the spinner will not be displayed on clicking the Spinner.

提交回复
热议问题