Handling very fast button click on Android -
i have "+" , "-" button increase/decrease quantity of item.
i need send network request (hitting webservice) everytime quantity changed.
the problem is, user "spam" "+" , "-" button. example, might pressed 3 times in second.
in regard of case, wait second, , send network request based on last quantity. reduce number of requests need (from 3 requests 1 request, in case).
what recommended way this?
can solve problem using postdelayed
in onclick
?
i think can try this
private long lastclick; void onclick(view view) { lastclick = system.currenttimemillis(); new handler().postdelayed(new runnable() { @override public void run() { if (system.currenttimemillis() - lastclick >= 1000) { makenetworkrequest(); } } }, 1000); }
this code skip first requests , run last request after 1 second pause
Comments
Post a Comment