button up down event problem

ygz12345

Member
Licensed User
Longtime User
simple code here where button1 tag=s and text = 0
B4X:
Sub Process_Globals

End Sub

Sub Globals
   Dim Button1 As Button
   Dim Label1 As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)

   Activity.LoadLayout("Layout1")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Down
   Label1.Text=Button1.Tag
End Sub
Sub Button1_Up
   Label1.Text=Button1.Text
End Sub

What im trying to do is when button1 is down , label1 show 'w' and button1 is up, label1 show '0'.

but when i press down and holding button1 , the label show 'w' then '0' and finally 'w'. Seem like the button is triggered down , up , down .

while for realising the button, its normal. only showing '0'

trying on sony xperia sola and samsung note 2, both return same problem.
but trying on emulator, there is no such problem.

any idea ??
 
Last edited:

Jerez

Active Member
Licensed User
Longtime User
I'm having the same problem with an ASUS ME301T.

I've same problem with a Lenovo S960.... with Sony E4 and Motorola works fine. Any workaround?
 
Upvote 0

WAZUMBi

Well-Known Member
Licensed User
Longtime User
A good but perhaps unnecessarily complex solution would be to use gestures.

You could then use the screen coordinates of where your touch event happened to determine which button was pressed and released.
 
Upvote 0

Jerez

Active Member
Licensed User
Longtime User
Seems like some devices change the internal behavior of buttons. This issue was discussed several times. Up until now there is no good solution.

A good but perhaps unnecessarily complex solution would be to use gestures.

You could then use the screen coordinates of where your touch event happened to determine which button was pressed and released.

Hi, i've fixed the problem with:

B4X:
Dim myButton As Reflector
 
    myButton.Target = Button1

    myButton.SetOnTouchListener("myButton")

B4X:
Sub myButton(ViewTag As Object, Action As Int, X As Float, Y As Float, MotionEvent As Object) As Boolean

    Select Case Action
     
        Case 0: 'Press
         
            'code here when the button is pressed ("down" equivalent)
         
        Case 1: 'Release
         
            'code here when the button is released ("up" equivalent)
         
     
    End Select
 
 
End Sub
 
Upvote 0
Top