Android Question Changing a ImageView upon click

Servaas

Member
Licensed User
Trying to change a Imageview upon clicking but this does not seem to do anything, do I need to load the .png files first?

B4X:
If Gopher1.Bitmap = LoadBitmap(File.DirAssets, "molealive.png") Then
        Gopher1.Bitmap = LoadBitmap(File.DirAssets, "molehit.png")
    Else
        Gopher1.Bitmap = LoadBitmap(File.DirAssets, "molealive.png")
    End If
 

mangojack

Expert
Licensed User
Longtime User
Use the Tag property to store the loaded image ... Gopher1.Tag = "molealive"

Then ..
B4X:
If Gopher1.Tag = "molealive" Then 
   Gopher1.Bitmap = LoadBitmap(File.DirAssets, "molehit.png")
   Gopher1.Tag = "molehit"
Else 
   Gopher1.Bitmap = LoadBitmap(File.DirAssets, "molealive.png")
   Gopher1.Tag = "molealive"
End If

If you are constantly swapping / loading images it might be an idea to load the images to variable bitmaps once at app start then use them in your ImageView.
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…