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
final boolean[] isLongPress = {false};
final int duration = 3000;
final Handler someHandler = new Handler();
final Runnable someCall = new Runnable() {
@Override
public void run() {
if(isLongPress[0]) {
// your code goes here
}
}
};
someButton.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int eventAction = event.getAction();
if(eventAction == MotionEvent.ACTION_DOWN){
isLongPress[0] = true;
someHandler.postDelayed(someCall, duration);
}
else if (eventAction == MotionEvent.ACTION_UP) {
isLongPress[0] = false;
someHandler.removeCallbacks(someCall);
}
return false;
}
});