Reputation: 21
Is there a way to measure a touch duration of an ImmageButton in android? I'm building an app that needs to use this data but all I've found was ensuring minimal duration
Upvotes: 1
Views: 363
Reputation: 2594
you should use setOnTouchListener
here you go
button.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN){
//start calculate your time here
startTime = System.currentTimeMillis();
}
if(event.getAction() == MotionEvent.ACTION_UP){
estimatedTime = System.currentTimeMillis() - startTime;
}
return true;
}
});
Upvotes: 1