Android Question Start/Stop option in one single button

ginsh

Member
Licensed User
Longtime User
Hi,

I am trying use one single button to do the below to change the button name. But it is not working.

By default the Button1.text = "Start"

B4X:
Sub Button1_Click
If Button1.text = “Start” then
Button1.text = “Stop”
End If
If Button1.text = “Stop” then
Button1.text = “Start”
End If
End Sub

Please anyone help me out.
 

mangojack

Expert
Licensed User
Longtime User
Hi,

I am trying use one single button to do the below to change the button name. But it is not working.

Try ...
B4X:
Sub Button1_Click
If Button1.text = “Start” then
  Button1.text = “Stop”
Else
  Button1.text = “Start”
End If
End Sub
 
Upvote 0

elitevenkat

Active Member
Licensed User
Longtime User
B4X:
Sub Button1_Click
If Button1.text = “Start” then
   Button1.text = “Stop”
else
  Button1.text = “Start” then
EndIf
End Sub
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You should go through your code to understand what exactly happens an why your code doesn't work.
I suggest you to put a breakpoint at the line If Button.Text = “Start” Then and execute the code step by step.
So you can see the program flow, and check the evolution of Button.Text property.
Another solution would be to use a ToggleButton, they are designed for this and have two Text propeties, TextOn and TextOff.
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…