I'm a beginner to android. I need to determine the touched time duration of android activity. As an example, When user touch and hold the screen, after 5 seconds, I need to show a toast(this scenario should be done in user's touch time period. In other words not in action up event). Is this possible? I tried with this.
public boolean onTouchEvent(MotionEvent event) {
int eventaction = event.getAction();
switch (eventaction) {
case MotionEvent.ACTION_DOWN:
pressTime = event.getDownTime();
break;
case MotionEvent.ACTION_UP:
eventTime = event.getEventTime();
//Toast.makeText(this, (eventTime - pressTime)+"", 100).show();
if (pressTime <= 5000) {
Toast t = Toast.makeText(this, "5 sec", 5);
t.show();
}
if (pressTime > 7000) {
Toast t = Toast.makeText(this, "5 sec to 20 sec", 5);
t.show();
}
}
This is working when the action up event. I need to do it in the touching time period.
Thanks in Advance.