I am listening for a View\'s long click events via setOnLongClickListener(). Can I change the long click delay / duration?
This was the simplest working solution I found to this restriction:
//Define these variables at the beginning of your Activity or Fragment:
private long then;
private int longClickDuration = 5000; //for long click to trigger after 5 seconds
...
//This can be a Button, TextView, LinearLayout, etc. if desired
ImageView imageView = (ImageView) findViewById(R.id.desired_longclick_view);
imageView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
then = (long) System.currentTimeMillis();
} else if (event.getAction() == MotionEvent.ACTION_UP) {
if ((System.currentTimeMillis() - then) > longClickDuration) {
/* Implement long click behavior here */
System.out.println("Long Click has happened!");
return false;
} else {
/* Implement short click behavior here or do nothing */
System.out.println("Short Click has happened...");
return false;
}
}
return true;
}
});