Android Example Simple switch button with image view

The application I'm writing I need switches, but not being an expert I arranged with some simple line of code. The result is good and does its work.
I used an image view and an int variable.
How the example attached, I change the image depending on the state of button and set a variable to store the state of the button.
Surely there are more sophisticated methods, and the experts will be able to add improvements and suggestions.

With this method you can only use images but not text. I have saved dozens of png images for everyone at this link:

You can use them at your leisure.

#Region  Project Attributes
    #ApplicationLabel: Slide Button
    #VersionCode: 1
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: true
#End Region

#Region  Activity Attributes
    #FullScreen: false
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Dim but1 As ImageView
    Dim set1 = 0 As Int

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:

    but1.SetLayout(42%x, 5%y, 16%x, 5%y)
    but1.Bitmap = LoadBitmap(File.DirAssets, "but 2 OFF.png")

End Sub

Sub but1_Click
If set1=1 Then
but1.Bitmap = LoadBitmap(File.DirAssets, "but 2 ON.png")
'your ON Sub
but1.Bitmap = LoadBitmap(File.DirAssets, "but 2 OFF.png")
'your OFF Sub
End If
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub


    110.8 KB · Views: 932
  • screen.png
    32.9 KB · Views: 1,396
  • 2015-04-07 23_30_37-slide.png
    2015-04-07 23_30_37-slide.png
    163.5 KB · Views: 1,261
Last edited: