Android Example Simple switch button with image view

Discussion in 'Tutorials & Examples' started by anallie0, Apr 7, 2015.

  1. anallie0

    anallie0 Active Member Licensed User

    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.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

    Attached Files:

    Last edited: Apr 9, 2015
    RauchG, ellpopeb4a, MaFu and 5 others like this.
  2. ivanomonti

    ivanomonti Well-Known Member Licensed User

  3. Ferbis

    Ferbis Member Licensed User

    Simple and elegant. Thanks
  4. r.babazadeh

    r.babazadeh Member Licensed User

  5. Juzer Hussain

    Juzer Hussain Active Member Licensed User

  6. Juzer Hussain

    Juzer Hussain Active Member Licensed User

    image collection is wonderful, switchbutton project is not working some little bugs.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice