Android Question Button down problem

Discussion in 'Android Questions' started by Devv, May 15, 2015.

  1. Devv

    Devv Active Member Licensed User

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

    Code:
    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 ?
     
  2. hogiebaer

    hogiebaer Active Member Licensed User

    Use Button2_Click !!!!!

    The _down event fires permanent while the button is pressed.
     
  3. Devv

    Devv Active Member Licensed User

    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
     

    Attached Files:

  4. klaus

    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.
     
    Devv likes this.
  5. hogiebaer

    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
     
    Devv likes this.
  6. hogiebaer

    hogiebaer Active Member Licensed User

    Hi Klaus,

    it's very strange. i have test :

    Code:
    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
     
  7. Devv

    Devv Active Member Licensed User

    "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 ?
     
  8. klaus

    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.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice