Android Question [Solved] Prevent rapid Button_Click?

anOparator

Active Member
Licensed User
Longtime User
I have a next and a previous button, each will:
increment 3 process_globals in Starter,
run 3 Subs loading a bitmap in 3 seperate imageviews
and do 3 kvs.Put statements.

If I click a button too fast too many times my counter variable goes from 13, 14, 15 to 116.
Would DoEvent in Button_Click be a way to prevent this or is there a better way?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Would DoEvent in Button_Click be a way to prevent this
No.

B4X:
Sub Button1_Click
 If DateTime.Now - LastActionTime < 300 Then Return
 LastActionTime = DateTime.Now
 ...
End Sub
LastActionTime is a process global variable.
 
Upvote 0

anOparator

Active Member
Licensed User
Longtime User
and a Long one at that , 200 is too small, 300 is just right. It turns 10 rapid Click events nto 5.
Thanks for the IDEa.
 
Upvote 0

DPaul

Active Member
Licensed User
Longtime User
Without me knowing how many clicks are to be expected...
Why don't you consider long_clicks ?
That would slow it down.
:)
 
Upvote 0

anOparator

Active Member
Licensed User
Longtime User
Without me knowing how many clicks are to be expected...
Why don't you consider long_clicks ?
That would slow it down.
:)
There's no way of knowing how fast the end user will click the button, I merely wanted to protect Counter1 from very rapid Button1_Clicks.
Long_click has its' use but not in this case, the code snippet above is more user friendly with a Tap-Tap-Tap feel, more adjustable, and does the job at 300 milliseconds.
Thanks for mentioning the long_click option.
 
Upvote 0
Top