management button with xml

Mr Blue Sky

Active Member
Licensed User
Longtime User
:signOops:, I looked everywhere and I find nothing to help me

1) have one button two position



2) Type : button


3) and one XML file to one apache server ex: 192.168.1.2/device.xml
<?xml version="1.0" encoding="utf-8"?>
<devices>
<switch>
<switch_1>0</switch_1>
</switch>

My Question
I want the application check my xml and if :
switch_1 = 1 the button is ON
switch_1 = 0 the button is OFF

if i clic to my button and change ON/OFF
i save in the xml file the new valeur 0 or 1

:sign0013: if I'm not in the right category, I seek an indication for setting this up.

thank you
 

Theera

Expert
Licensed User
Longtime User
Hi there,

Try see Klaus's strategy.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Instead of a Button you could use a ToggleButton.
ToggleButtons have two states checked and unchecked (on or off)
You can set the state with ToggleButton.Checked = False or ToggleButton.Checked = True
And use the ToggleButton_CheckedChange(Checked As Boolean) event to catch the state changes.
Be aware that the Checked variable is Boolean, so you should save False or True or you must convert yourself 0 to False and 1 to True.

Best regards.
 
Upvote 0

Mr Blue Sky

Active Member
Licensed User
Longtime User
Thank Klaus for your information all it good now

Sub Globals
Dim Client As HttpClient
Dim Request As HttpRequest
Dim btSwitch1 As ToggleButton
Dim checked, unchecked As BitmapDrawable
checked.Initialize (LoadBitmap(File.DirAssets, "boutonon.png"))
unchecked.Initialize (LoadBitmap(File.DirAssets, "boutonoff.png"))
End Sub

Sub Activity_Create(FirstTime As Boolean)
Dim StateSwitch As StateListDrawable
StateSwitch.Initialize
StateSwitch.AddState(StateSwitch.State_Checked, checked)
StateSwitch.AddState(StateSwitch.State_Unchecked, unchecked)
btSwitch1.Background = StateSwitch
End Sub

Sub btSwitch1_Click
If (btSwitch1.Checked = True) Then
Request.InitializeGet("http://192.168.xxx.xxx/digital_out1.php?ordre=ON")
Request.Timeout = 10000
If Client.Execute(Request,1) = False Then Return
Else
If (btSwitch1.Checked = False) Then
Request.InitializeGet("http://192.168.xxx.xxx/digital_out1.php?ordre=OFF")
Request.Timeout = 10000
If Client.Execute(Request,1) = False Then Return
End If
End If
End Sub

Sub Client_ResponseError (Reason As String, StatusCode As Int, TaskId As Int)
Msgbox(Reason, "error")
End Sub

Sub Client_ResponseSuccess (Response As HttpResponse, TaskId As Int)
'' Msgbox(Response.GetString("UTF8"), "success")
End Sub
 
Last edited:
Upvote 0

Mr Blue Sky

Active Member
Licensed User
Longtime User
No problem Klaus the newbie is me ;-) i'm open for all idea. Thank again you help me to much already. :sign0098:

Best regards.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…