Issue
I have a Click function and long press on the same button. Implemented the long press event but, I need to find the button UP_EVENT and DOWN_EVENTS separately.
How can I implement by using the OnLongClickListener
View.OnLongClickListener listener = new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
return true;
}
};
Solution
Implement a TouchListener within the onLongClickListener:
View.OnLongClickListener listener = new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
view.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// PRESSED
return true; // if you want to handle the touch event
case MotionEvent.ACTION_UP:
// RELEASED
return true; // if you want to handle the touch event
}
return false;
}
});
return true;
}
};
Answered By – TejjD
Answer Checked By – Timothy Miller (AngularFixing Admin)