Android Question Button down problem

Devv

Active Member
Licensed User
Why button down sub is launched two time when i hold the button down then release it ?

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("main")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub



Sub Button2_Down
    vib.Vibrate(100)
End Sub


the phone will vibrate 2 times why ?
 

Devv

Active Member
Licensed User
Use Button2_Click !!!!!

The _down event fires permanent while the button is pressed.
i tried this on 2 devices , it will not "fires permanent while the button is pressed" it only fires 2 times.
please try attached code on your device and let me know
 

Attachments

  • b4atest.zip
    11.9 KB · Views: 85
Upvote 0

klaus

Expert
Licensed User
On my Sony xperia z1 the Down event is also fired two times.
What exactly do you expect from the Down event ?
I don't think that it will fire 'permanently'.
In my mind it should fire once when the Button is pressed and when the Button is released Button_Up fires once.
If you want the Button to fire in time intervals as long as the Button is pressed you could do it with a Timer.
Enable the Timer in Button_Down and disable it in Button_Up and call your routine in Timer_Tick.
From what I've seen is that when you press the button Button_Down is fired, then Button_Up is fired and when you leave the button pressed Button_Down is fired a seond time and Button_Up is fired again when you release the button.
 
Upvote 0

hogiebaer

Active Member
Licensed User
Hi Devv,

i seems i have missunderstood the _down event from buttons.
The "normal planned" function of the _down event is to fire ONCE you pressed.
And the _up event don't work properly on my device

Sorry
 
Upvote 0

hogiebaer

Active Member
Licensed User
Hi Klaus,

it's very strange. i have test :

B4X:
Sub Button1_Down
  nn1=nn1+1
  Button1.text="DownCount="&nn1&"  UpCount="&nn2
End Sub

Sub Button1_Up
  nn2=nn2+1
  Button1.text="DownCount="&nn1&"  UpCount="&nn2
End Sub

The result is strange. If you press the button and hold , both! Counter are increased 2times:eek::confused:
And if you release the button, only 1 time in _UP Event
 
Upvote 0

Devv

Active Member
Licensed User
On my Sony xperia z1 the Down event is also fired two times.
What exactly do you expect from the Down event ?
I don't think that it will fire 'permanently'.
In my mind it should fire once when the Button is pressed and when the Button is released Button_Up fires once.
If you want the Button to fire in time intervals as long as the Button is pressed you could do it with a Timer.
Enable the Timer in Button_Down and disable it in Button_Up and call your routine in Timer_Tick.
From what I've seen is that when you press the button Button_Down is fired, then Button_Up is fired and when you leave the button pressed Button_Down is fired a seond time and Button_Up is fired again when you release the button.

"In my mind it should fire once when the Button is pressed and when the Button is released Button_Up fires once."
i expected this also , but it is not acting like this , should i write about this in bugs section ?
 
Upvote 0

klaus

Expert
Licensed User
I am not sure if it is the 'normal' behaviour from the Android point of view or if it is a B4A problem.
Erel, could you give your point of view.
@hogiebaer
On my device both events are fired once or twice.
Once each with short press and twice each with a long press.
 
Upvote 0
Top