Reputation: 960
I have implemented scroll view and I need to detect the visibility of the view when scrolling and trigger that event once per screen initialization. But, at random times, I get it triggered multiple times in a very short time (a few ms), and it messes up with my logic in VM.
Is there a way to restrict this triggering and make it trigger once every 100ms or something similar?
Upvotes: 1
Views: 439
Reputation: 23234
An easy way to do this is something like this right where the trigger happens
if (System.currentTimeMillis() - lastTime < 100)
return
else {
lastTime = System.currentTimeMillis()
// rest of your code
}
where lastTime
is just some variable you keep in your class
Upvotes: 1