Change Image Depending on value

Stulish

Active Member
Licensed User
Longtime User
Hi all,

How would i change an imageview depending on data in a program.

I have 16 imageviews labelled imageView1......to....imageView16

can i declare an imageview in a sub and then assign a particular imageView1-16 to the imageview i have just declared.

it is so i don't have to repeat code over and over

my thought process is below:

B4X:
Sub Draw_Image (pos as int, cView as Boolean)
   Dim curIm As ImageView 
   If pos = 1 then curIm = ImageView1
   If pos = 2 then curIm = ImageView2   
   If pos = 3 then curIm = ImageView3
   If pos = 4 then curIm = ImageView4

   If cView = true Then 
      curIm.Bitmap = LoadBitmap(File.DirAssets,"picture1.png")
   Else
      curIm.Bitmap = LoadBitmap(File.DirAssets,"picture2.png")
   End If
End Sub
 
Last edited:

Stulish

Active Member
Licensed User
Longtime User
How???

:)
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
As in your code:

B4X:
Sub Draw_Image (pos as int, cView as Boolean)
    Dim curIm As ImageView 
    If pos = 1 then
          curIm = ImageView1
    Else If pos = 2 then
          curIm = ImageView2    
    end if

    If cView = true Then 
        curIm.Bitmap = LoadBitmap(File.DirAssets,"picture1.png")
    Else
        curIm.Bitmap = LoadBitmap(File.DirAssets,"picture2.png")
    End If
End Sub
 
Upvote 0

Stulish

Active Member
Licensed User
Longtime User
Thanks,

I wondered why the sub wasn't working, and didn't seem to be doing anything.

Next time i will remember to actually call the sub

:sign0104:

Thanks

Stu
 
Upvote 0
Top