开发者

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 doe开发者_运维百科s. is this possible?? thanks.


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;
        }

    });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜