Android Question Button_Down, Button_Up events fire twice

MartinR

Member
Licensed User
This issue has been raised before, but as a newbie I've just come across it. I want to run some code once when I press a button, start a timer, and for the code to be repeated under timer events until I release the button. The problem is that the button_down event runs twice: in fact I get _down, _up, _down events. (If I press/release the button quickly I do get just one _down,_up sequence.)

In one post on this topic it was suggested that this is a known issue, and using a panel instead of a button would solve the problem. Is this true?

I notice that when using the Designer to add buttons and button-events the _down and _up events are no longer listed as options. (B4A v 7.0) Are they deprecated?

Edit: I now see that Erel advises (when hovering over Button keyword) that the _down and _up button events may not work on some devices. Apologies for unnecessary post!
 
Last edited:

ronell

Well-Known Member
Licensed User
Longtime User
In one post on this topic it was suggested that this is a known issue, and using a panel instead of a button would solve the problem. Is this true?

yes, you can use panel touch events
B4X:
Sub panel_Touch (Action As Int, X As Float, Y As Float)
Select Action
        Case Activity.ACTION_DOWN
          '_down
            timer1.initialized("timer1",1000)
            timer1.enabled = True
        Case Activity.ACTION_UP
          '_up
           timer1.enabled = False
        Case Activity.ACTION_MOVE
        
    End Select

End Sub
 
Upvote 0

MartinR

Member
Licensed User
Have experimented with buttons and panels, on a phone and on a tablet.
App comprises one button, one panel and four labels to record up and down events on the button and up and down touch actions on the panel.

B4X:
Sub btn1_down
    lblBTNDown.Text=lblBTNDown.Text + 1
End Sub

Sub btn1_up
    lblBTNUp.Text=lblBTNUp.Text + 1
End Sub   

Sub pnl1_touch(ACTION As Int,X As Float,Y As Float)
    If ACTION = Activity.ACTION_DOWN Then
        lblPNLDown.Text=lblPNLDown.Text + 1
    Else If ACTION = Activity.ACTION_up Then
        lblPNLUp.Text=lblPNLUp.Text + 1
    End If
End Sub

The labels for the button events show one increment for a quick, light tap, but always at least two downs and an up for one steady press (followed by an up for the release).

The panel does behave as expected: one increment for touching the panel then one for releasing.

My phone (BLU ENERGY DIAMOND) behaves better than my tablet (LENOVO Tab 3 7). Pressing firmly and continuously on the tablet causes the labels to carry on incrementing somewhat randomly, even the labels associated with the panel. A gentle, continuous touch on the panel is OK. Clearly there is a hardware issue here for the tablet. However, I think there is definitely a bug with the button_down and button_up events triggering incorrectly.

I'll use some panels for my particular app for the time being.

Thanks
 
Upvote 0
Top