How can i add click functions to imageviews which are in a scroll box?

mangojack

Expert
Licensed User
Longtime User
Try this ..

B4X:
Sub Activity_Create(FirstTime As Boolean)
   
   Dim ImageView1 As ImageView
   ImageView1.Initialize("Image")  'the assigned Event Name  is "Image"
   
   ScrollView1.Panel.AddView(ImageView1,0,0,100dip,100dip)
   
End Sub

Sub Image_Click

   Log("Click Test")

End Sub

Cheers mj
 
Upvote 0
I have tried all of these in a click activity with no success.

B4X:
Sub setupscrollview
   Dim level1button As ImageView
   Dim level1buttonimage As Bitmap
   level1buttonimage.Initialize(File.DirAssets, "level1button.png")
   level1button.Initialize("levelbutton")
   level1button.Bitmap = level1buttonimage
   Scroll1.Panel.AddView(level1button, 40, 20, 220, 220)
End Sub

Thanks, James.
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
james .. have a look at this .. maybe just mispelling "level1button" vs "levelbutton" ??

Cheers mj
 

Attachments

  • Level1.zip
    26.7 KB · Views: 133
Upvote 0

sorex

Expert
Licensed User
Longtime User
just wondering...

why don't you add them via the designer?

less code to write and you can right-click the imageview and select to add an onclick event.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
this works on my tablet

B4X:
Sub setupscrollview
Dim level1button As ImageView 
Dim level1buttonimage As Bitmap
Dim level2button As ImageView 
Dim level2buttonimage As Bitmap

level1buttonimage.Initialize(File.DirAssets,"level1.gif")
level1button.Initialize("level1")
level1button.Bitmap=level1buttonimage
Scroll1.Panel.AddView(level1button,40,20,128,64)

level2buttonimage.Initialize(File.DirAssets,"level2.gif")
level2button.Initialize("level2")
level2button.Bitmap=level2buttonimage
Scroll1.Panel.AddView(level2button,40,80,128,64)
End Sub

Sub level1_Click
ToastMessageShow("level1",False)   
End Sub

Sub level2_Click
ToastMessageShow("level2",False)   
End Sub
 

Attachments

  • scrollview_image_clicks.zip
    17.1 KB · Views: 154
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…