You can use OnTouchListener:
private int lastTouchedViewId = -1;
private long duration = System.currentTimeMillis();
private long LONG_CLICK_DURATION = 1000;
...
view.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
if (lastTouchedViewId != view.getId()) {
lastTouchedViewId = view.getId();
duration = System.currentTimeMillis();
}
else
{
if(duration-System.currentTimeMillis()> LONG_CLICK_DURATION)
doStuff();
}
return true;
case MotionEvent.ACTION_UP:
lastTouchedViewId = -1;
return true;
}
return false;
}
});
source
share