Android Question Tag in ImageView not holding a'Type' variable?

rafaelmotaquintana

Active Member
Licensed User
I have this declaration :

B4X:
   Type FolderFile (tFolder As String, tFile As String)
   Dim Ff As FolderFile

Later, in a sub, I generate several images, each with different tags

B4X:
      For nF = 0 To fileList.Size-1
            ImageFile = fileList.Get(nF)

        Dim Im As ImageView
        Im.Initialize("MenuImageEdit")
       
        ff.tfolder = lfolder
        ff.tfile = ImageFile
        Im.tag = ff

        PanelImages.AddView(Im,LeftImg ,ImageY,AnchoPanel,AnchoPanel)
        Im.Gravity = Gravity.FILL
        Im.Bitmap=f.LoadBitmapSample2(lFolder,limagen,AnchoPanel,AnchoPanel,True)
        LeftImg = LeftImg + AnchoPanel + 5dip
        IndexPanel = IndexPanel + 1
        If IndexPanel = CantPanels Then
            IndexPanel = 0
            LeftImg = 0
            ImageY = ImageY + AnchoPanel + 5dip
        End If
    Next

The problem is, when I click the image, always the Tag returns the last value, corresponding to the last image.
Weird thing is that if I dont use the variable FF, but use the integer nF, I get the correct result (0,1,2,3,4 etc).



B4X:
Sub MenuImageEdit_Click
    Dim listOpt As List, im As ImageView, FF2 as FolderFile
    im = Sender
    FF2 = im.Tag
    listOpt.Initialize
    listOpt.AddAll(Array As String("View Image","", ""))
    Dim xId As id, wResult As Int
    wResult = xId.InputList1(listOpt,"IMAGE")
    Select wResult
        Case 0
            f.ViewImage(FF2.tFolder, FF2.Tfile)  ' <------ HERE, ALWAYS THE LAST IMAGE DATA
        Case 1
    End Select
   
End Sub


Please help me with this
 

JordiCP

Expert
Licensed User
Longtime User
You should declare ff each time as a new folderFile inside the for loop. Otherwise (when ff is declared in GLobals), you are assigning the same tag to all the imageViews and only modify its contents. So, all the imageviews will have the same variable as a tag (and its contents will be the last one assigned)
 
Upvote 0

eurojam

Well-Known Member
Licensed User
Longtime User
you have to add in your loop:
B4X:
For nF = 0 To fileList.Size-1
Dim Ff As FolderFile 'that is from Jordis post
ff.initialize
...
next
 
Upvote 0

eurojam

Well-Known Member
Licensed User
Longtime User
You should declare ff each time as a new folderFile inside the for loop. Otherwise (when ff is declared in GLobals), you are assigning the same tag to all the imageViews and only modify its contents. So, all the imageviews will have the same variable as a tag (and its contents will be the last one assigned)
again second....you are quite quick this night;)
 
Upvote 0
Top