In an application I\'m working on, I have the requirement that a user must click & hold a component for a period time before a certain action occurs.
I\'m curren
I found a simple solution studying how the long press event works.
Each time a view is clicked, a Runnable
of type CheckForLongPress
is added to a queue with a delay. If the delay ends, the OnLongClickListener
is called. If there is a different event before the delay ends, then, the CheckForLongPress Runnable
is removed from de queue.
I just override the public method postDelayed(Runnable action, long delayMillis)
of the view to change the OS delay
@Override public boolean postDelayed(Runnable action, long delayMillis) {
boolean isLongPress = action.getClass().getSimpleName().equals("CheckForLongPress");
return super.postDelayed(action, isLongPress ? LONG_PRESS_MILLIS : delayMillis);
}
I set LONG_PRESS_MILLIS
to 100 and it's working!
Hope it helps!!! ;)