2016-08-23 60 views
0

设置了onTouchonClick的事件处理程序。我希望onTouch事件能够阻止onClick。我将如何做到这一点?使用onTouch忽略onClick

如果满足onTouch条件,那么onClick永远不会被调用。

回答

0

按照Android框架如果实现了onTouchListener该视图

@Override 
    boolean onTouch(View view, MotionEvent motionEvent) { 
     case R.id.send: 
      switch(motionEvent.getAction()){ 
       case MotionEvent.ACTION_DOWN: 
        //when the user has pressed the button 
        //do the needful here 
        break; 
       case MotionEvent.ACTION_UP: 
        //when the user releases the button 
        //do the needful here 
        break; 
      }`enter code here` 
      break; 
    } 
    return true; 
} 

onTouch方法返回true,将阻止其他行动,包括点击事件

0

只需从onTouch侦听器返回true,并且点击将永远不会注册。