I am trying to detect when the user releases an ImageButton
long click using this answer, however, I noticed the OnLongClickListener
runs twice, I fixed it by returning true instead of false inside the onTouchListener
like this:
private View.OnLongClickListener longClickListener = new View.OnLongClickListener() {
@Override
public boolean onLongClick(View pView) {
Log.d("Record", "Start");
isSpeakButtonLongPressed = true;
return true;
}
};
private View.OnTouchListener touchListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View pView, MotionEvent pEvent) {
pView.onTouchEvent(pEvent);
if (pEvent.getAction() == MotionEvent.ACTION_UP) {
if (isSpeakButtonLongPressed) {
Log.d("Record", "stop");
isSpeakButtonLongPressed = false;
}
}
return true;
}
};
I don't know why this fixed the issue and if it is correct doing this. glad for some explanation.