Reputation: 20132
i have following code...
public boolean onTouch(View view, MotionEvent me) {
//here i want to know the time of touch
switch (me.getAction()) {
case MotionEvent.ACTION_DOWN: { }
case MotionEvent.ACTION_UP: { }
-
-
-
}
}
Any Idea?
Upvotes: 0
Views: 4271
Reputation: 45942
It is pretty simple
public yourClass{
long down;
public boolean onTouch(View view, MotionEvent me) {
//you don't need here the difference because it might be a down action!
//you need the difference when the up action occurs
switch (me.getAction()) {
case MotionEvent.ACTION_DOWN:
down = System.currentTimeMillis();
break;
case MotionEvent.ACTION_UP:
//this is the time in milliseconds
long diff = System.currentTimeMillis() - down;
break;
}
}
}
Upvotes: 7
Reputation: 1249
I suppose you want to measure the time between the two events. This is very simple. All you need is to find an API method which returns the current time. In this case android.os.SystemClock.elapsedRealtime() or .uptimeMillis() should serve you (android documentation).
When the first event occurs, you save the current time in a variable. On the second event you just calculate the difference between the current time and the value you stored before.
Upvotes: 2
Reputation: 23873
You can use
System.currentTimeMillis();
to capture the times on each event
Upvotes: 0