Android Question click event from array of views from layout file

azclay

Member
Licensed User
hello can someone explain to me why this very basic code does not do what i expect it to do please?

B4X:
Sub Globals
    Private iv1 As ImageView
    Private iv2 As ImageView
    Private ivs() As ImageView
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("viewarraylay")
    ivs  = Array As ImageView(iv1,iv2)
End Sub

Sub ivs_click
    Dim iv As ImageView
    iv = Sender
    iv.Visible=False
    iv.Invalidate
End Sub
i would expect the clicked imageview to disappear.
i know it is something simple and aside from the fact they are imageviews and not buttons i believe it is identical to the code in the documentation example. it does not produce an error or a result.
thanks
 

DonManfred

Expert
Licensed User
Longtime User
Did you set the event name in the imageviews (in both) to ivs?
Best is to upload a small project
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
there is no need to declare the views in global variables unless you wish to edit / change view properties in code later.
edit the Event Name for each view to "ivs" in the designer ..


B4X:
Sub Globals
  
End Sub

Sub Activity_Create(FirstTime As Boolean)
  Activity.LoadLayout("viewarraylay")   
End Sub

Sub ivs_click
    Dim iv As ImageView
    iv = Sender
    iv.Visible=False   
End Sub

>>>>>>> And @DonManfred is way to fast .... :)
 
Upvote 0
Top