【发布时间】:2015-11-23 22:46:14
【问题描述】:
我有一个按钮,我试图在一个按钮中触发两个动作。
在按钮长按时调用方法takeVideo。在按钮按下时我想调用方法imageCapture。
以下代码可用于长按。但我无法检测到按下按钮以仅调用 imageCapture 方法。
takePhotoBtn.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
long down;
int action = motionEvent.getAction();
if (action == MotionEvent.ACTION_BUTTON_PRESS) {
imageCapture();
return true;
}
if (action == MotionEvent.ACTION_DOWN) {
takeVideo();
timer.start();
return true;
} else if (action == MotionEvent.ACTION_UP) {
takeVideo();
timer.cancel();
return true;
}
return false;
}
});
编辑
我没有使用OnLongClickListener 和OnClickListener。
我想在MotionEvent.ACTION_UP 上执行其他操作,所以我尝试在这种情况下使用setOnTouchListener 来解决我的问题
【问题讨论】:
-
谢谢,但我想用
setOnTouchListener解决我的问题
标签: android button ontouchlistener