Andy Lobel
Andy Lobel

Reputation: 3416

Make a spinner do stuff when its clicks in android?

i have a spinner and i want it so that when the actual spinner is clicked (not an item inside it) to execute some code, like a button does. is this possible?? thanks.

Upvotes: 0

Views: 2612

Answers (1)

Bobbake4
Bobbake4

Reputation: 24857

You might want to try and set a listener for setOnCreateContextMenuListener(OnCreateContextMenuListener listener) I'm not sure if that will work. You could also try and set a listener for setOnTouchListener(OnTouchListener listener). Both of those would be set on the spinner object. Try either of those they might get fired when you actually click the spinner.

Ex:

    Spinner spinner = this.findViewById(R.id.spinner);
    //First Listener
    spinner.setOnCreateContextMenuListener(new OnCreateContextMenuListener(){

        @Override
        public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
            //Your code goes here
        }

    });
    //Second Listener
    spinner.setOnTouchListener(new OnTouchListener(){

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            //Your code goes here
            return false;
        }

    });

Upvotes: 2

Related Questions