嘿我做了一个自定义视图组扩展了相对布局并覆盖了onTouchEvent():
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
doMyWork();
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
endMywork();
break;
default:
break;
}
return super.onTouchEvent(event);
}
我还为listview添加了onItemClick监听器。但我无法收到:
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
在我的视图组中的事件......有人可以帮助我吗?
非常感谢!!!
答案 0 :(得分:0)
尝试:
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
doMyWork();
return true;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
endMywork();
break;
default:
break;
}
return super.onTouchEvent(event);
}