Thank you KlausWith this routine, needs the Reflection library.
B4X:'Returns the pressed state Sub isPressed(v As View) As Boolean Dim r As Reflector r.Target = v Return r.RunMethod("isPressed") End Sub
Thank you KlausYou should use code tags when you want to show code (the View attachment 22916 button) !
I would suggest you to use a Timer to do this.
In Sub btnm_Down you set the Timer1.Enabled = True.
In Sub btnm_Up you set the Timer1.Enabled = False.
And put the decrementing code in the Timer1_Tick routine.
With this routine, needs the Reflection library.
B4X:'Returns the pressed state Sub isPressed(v As View) As Boolean Dim r As Reflector r.Target = v Return r.RunMethod("isPressed") End Sub
Sub SetPressed(cmd As Button, Pressed As Boolean)
Dim ref As Reflector
ref.Target = cmd
ref.RunMethod2("setPressed", Pressed, "java.lang.boolean")
End Sub
Sub ButtonPressed_Click
Dim b5 As Button
Dim bb As String
b5 = Sender
bb = b5.Tag
Log(bb)
If bb = "1" Then
Log("here 1")
Dim check As Boolean
check = isPressed(bNormal)
If check = True Then
SetPressed(bNormal,False)
Else
SetPressed(bNormal,True)
End If
End If
If bb = "2" Then
Log("here 2")
Dim check As Boolean
check = isPressed(bCircle)
If check = True Then
SetPressed(bCircle,False)
Else
SetPressed(bCircle,True)
End If
End If
End Sub
Sub isPressed(cmd As Button) As Boolean
Dim r As Reflector
Dim PressedState As Boolean
r.Target = cmd
PressedState = r.RunMethod("isPressed")
Return PressedState
End Sub
Do you have a small test project so we could test it.
Hoe did you set the colors of the buttons.
Are you trying to set a kind of radiobuttons with buttons ?
You could replace the buttons by togglebuttons, these ones have two states.