Button stuck in 'pressed down' look?

Jim Brown

Active Member
Licensed User
Longtime User
Is there a way to avoid the following little issue ..

In my app I use a button to delete local items. As a precaution I employ the use of the LongClick() event (to avoid accidental clicks)
Once all items are deleted I disable the button

The problem is, the button remains in its "pressed-down" look

Views_LongPress.png


Try this simple example:

B4X:
' Button stuck in "Pressed Down" look from LongClick/Disable combo
Sub Process_Globals
End Sub

Sub Globals
   Dim bt As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
   bt.Initialize("ButtonPress") : bt.Text="Long-Press me"
   Activity.AddView(bt,10%x,20dip,60%x,40dip)
End Sub

Sub ButtonPress_LongClick()
   bt.Enabled=False
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Is there a method to avoid this situation? I tried various combinations of the following inside the LongClick() sub:
bt.Invalidate
bt.Visible=True .... False
DoEvents
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This looks like a bug in the Android SDK. Here is a workaround:
B4X:
Sub Process_Globals
   Dim tmrDisable As Timer
   Dim shouldDisable As Boolean
End Sub

Sub Globals
   Dim bt As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
      tmrDisable.Initialize("tmrDisable", 5)
   End If
   bt.Initialize("ButtonPress") : bt.Text="Long-Press me"
   Activity.AddView(bt,10%x,20dip,60%x,40dip)
End Sub
Sub ButtonPress_Up
   If shouldDisable Then
      tmrDisable.Enabled = True
      shouldDisable = False
   End If
End Sub
Sub ButtonPress_LongClick()
   shouldDisable = True
End Sub
Sub tmrDisable_Tick
   tmrDisable.Enabled = False
   bt.Enabled = False
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub
 
Upvote 0

Jim Brown

Active Member
Licensed User
Longtime User
Thanks for confirming Erel

I just found another work-around. Remove the view entirely then re-create it:
B4X:
' Button stuck in "Pressed Down" look from LongClick/Disable combo
' One solution to get around the issue
Sub Process_Globals
End Sub

Sub Globals
   Dim bt As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
   bt.Initialize("ButtonPress") : bt.Text="Long-Press me"
   Activity.AddView(bt,10%x,20dip,60%x,40dip)
End Sub

Sub ButtonPress_LongClick()
   bt.RemoveView
   bt.Initialize("ButtonPress") : bt.Text="Long-Press me"
   Activity.AddView(bt,10%x,20dip,60%x,40dip)
   bt.Enabled=False
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub
 
Upvote 0
Top