Android Question Button1.Enable

Isac

Active Member
Licensed User
Longtime User
Hello
How do I pass a false when the release button?
Thank You

B4X:
Sub Button1_Click
 
   
 If Button1.Enabled=True Then
    Button1.Text="ON"
    Else
    Button1.Text="OFF"
End If

End Sub
 

susu

Well-Known Member
Licensed User
Longtime User
B4X:
Sub Button1_Click

  
If Button1.Enabled=True Then
    Button1.Text="OFF"
    Button1.Enable = False
    Else
    Button1.Text="ON"
    Button1.Enable = True
End If

End Sub
 
Upvote 0

susu

Well-Known Member
Licensed User
Longtime User
That code won't work because once the button is disabled you cannot click on it, you should use a Toggle button.
You're right, I replied on my phone and did not check it on B4A.
 
Upvote 0

susu

Well-Known Member
Licensed User
Longtime User
It does not change the text, remains locked OFF

Sorry, I was wrong.
You can use 2 buttons ButtonOn and ButtonOff. You can change the state by using a global var then enable/visible it.
However, it's better to use Toggle button like NJDude suggested.
 
Upvote 0

ivan.tellez

Active Member
Licensed User
Longtime User
Thats easy...

B4X:
Sub Button1_Click

If Button1.Text="OFF" Then
    Button1.Text="ON"
    '...Code to turn on whatever
Else
    Button1.Text="OFF"
    '...Code to turn off whatever
End If

End Sub

Note that the button is never actually disabled.
 
Last edited:
Upvote 0

Isac

Active Member
Licensed User
Longtime User
:)

B4X:
Sub Button1_Click

If Button1.Text="OFF" Then
    Button1.Text="ON"
    ...Code to turn on whatever
Else
    Button1.Text="OFF"
    ...Code to turn off whatever
End If

End Sub
 
Upvote 0
Top