开发者

Using removeCallbacks

I have set a button onTo开发者_开发问答uchListener 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.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜