0
设置了onTouch
和onClick
的事件处理程序。我希望onTouch
事件能够阻止onClick
。我将如何做到这一点?使用onTouch忽略onClick
如果满足onTouch
条件,那么onClick
永远不会被调用。
设置了onTouch
和onClick
的事件处理程序。我希望onTouch
事件能够阻止onClick
。我将如何做到这一点?使用onTouch忽略onClick
如果满足onTouch
条件,那么onClick
永远不会被调用。
按照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,将阻止其他行动,包括点击事件
只需从onTouch侦听器返回true,并且点击将永远不会注册。