android - On touch listener will not fire up when the user is too fast -


i have ontouchlistener , waiting action , down events. when user touches surface quick/short down event fire , not event. fixed temporarily sleep thread know sure not ideal solution. have better idea?

button mybutton = (button) findviewbyid(r.id.button);   mybutton.setontouchlistener(new ontouchlistener() {          @override         public boolean ontouch(view view, motionevent motionevent) {                     long timelasttouch = system.currenttimemillis();                     if (motionevent.getaction() == motionevent.action_up) {                         long timetouchnow = system.currenttimemillis();                         if (timetouchnow -  timelasttouch < 400){                             return true;                         }                         return false;                     }                     if (motionevent.getaction() == motionevent.action_down) {                         long timenow = system.currenttimemillis();                         if ((timenow - timelasttouch) < 400) {                             // stuff                             return true;                         }                         return false;                     }             }             return false;         }     } }); 

tthis wrong way, not use sleep() method.

remove sleep() logic, , declare 1 variable , check last touch time , current touch time difference, if difference greater 400 millis execute if code.

if problem comment, solve issue, best luck.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -