views:

45

answers:

1

I have set a button onTouchListener and I would like to replace it with another listener. I believe that I need to use the removeCallbacks call before setting the new listener for the button, but I'm not sure how to use removeCallbacks and I'm not even sure if it's the right method to use. I originally set the listener like this:

mybutton.setOnTouchListener(new View.OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                some code here
            }});

Please advise.

+3  A: 

Just calling setOnTouchListener will replace the previous listener. Each View can have only one touch listener. The Android source code confirms this.

BTW As you suspected removeCallbacks is the wrong API, and is used with post()/postDelayed() to add runnables to the MessageQueue.

bramp