java - How to determine touched time duration in android -
java - How to determine touched time duration in android -
this question has reply here:
android touch event determining duration 3 answersi'm beginner android. need determine touched time duration of android activity. example, when user touch , hold screen, after 5 seconds, need show toast(this scenario should done in user's touch time period. in other words not in action event). possible? tried 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 20 sec", 5); t.show(); } }
this working when action event. need in touching time period.
thanks in advance.
check difference between press time , release time:
long holdtime = eventtime - presstime; if (holdtime > 7000 && holdtime < 20000) { toast t = toast.maketext(this, "5 sec 20 sec", 5); t.show(); } else if (holdtime > 5000 && holdtime <= 7000) { toast t = toast.maketext(this, "5 sec", 5); t.show(); }
java android
Comments
Post a Comment