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

    Hi
    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:
    https://drive.google.com/folderview...k3VEFZb2ZIQXFDQ0Iwb1c5M3p4bldyQlk&usp=sharing

    You can use them at your leisure.


    Code:
    #Region  Project Attributes
        
    #ApplicationLabel: Slide Button
        
    #VersionCode: 1
        
    #VersionName:
        
    '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:
        Activity.LoadLayout("slide")

        but1.SetLayout(
    42%x5%y16%x5%y)
        but1.Bitmap = 
    LoadBitmap(File.DirAssets, "but 2 OFF.png")

    End Sub

    Sub but1_Click
    set1=set1+
    1
    If set1=1 Then
    but1.Bitmap = 
    LoadBitmap(File.DirAssets, "but 2 ON.png")
    'your ON Sub
    Else
    set1=
    0
    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

    wonderful
     
  6. Juzer Hussain

    Juzer Hussain Active Member Licensed User

    image collection is wonderful, switchbutton project is not working some little bugs.
     
Loading...
  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