Android Question How to make a On/OFF button design

Douglas Farias

Expert
Licensed User
Longtime User
Hi all can i make a sound button on my app using 2 images

1.jpg = on
2.jpg = off

how can i make to dont need loadbitmap all time again and again when user press
have a way to load this 2 images at activity create and later only change when button press or i realy need use loadbitmap all time?
 

barx

Well-Known Member
Licensed User
Longtime User
use a toggle button and set the 2 images as the 2 states
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
but need use loadbitmap again?
can u give a sample to dont give me memory error?
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
Hi Douglas, you just need to create two global variables. Load the bitmaps to these and that's it. You don't need to load bitmap again, just call the global variables instead.

Regards,
RandomCoder
 
Upvote 0

Croïd

Active Member
Licensed User
Longtime User
B4X:
Dim Mygoback As Int : Mygoback = 1 ' =  toggle
Dim btnchange As Button
-----------------------------------------------------------------

Sub btnchange_Click
        Select Mygoback
              Case 1
btnchange.SetBackgroundImage(LoadBitmap(File.DirAssets, "go.png"))
              Case 2
btnchange.SetBackgroundImage(LoadBitmap(File.DirAssets, "back.png"))
              End Select
              Mygoback = Mygoback + 1
              If Mygoback > 2 Then
              Mygoback = 1
              End If
End Sub
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
load both images in activity create, then alternate their (visible) property of the two images. button image are very tiny so they will not consume much memory resources.
 
Upvote 0
Top