Android Question Button.Tag value inside xCustomListView

josejad

Expert
Licensed User
Longtime User
Hi¡¡

I have a xCustomListView with a text and a buttom to call camera.
When I create every Item,

B4X:
Sub CrearItemChk(Text As String, Index As Int, Width As Int, Height As Int) As Panel
    Dim p As Panel
    p.Initialize("")
    p.SetLayout(0, 0, Width, Height)
    p.LoadLayout("cellPuntosChk")
    LbPuntoChk.Text = Text
    BtCamera.Tag = Index
    Log(BtCamera.Tag)
    Return p
End Sub

The log show me the tags fine (0, 1, 2, ....)
But when I call the BtCamera_Click, the tag is always the last index. It seems BtCamera_Click is common.
How can I do to every button return its tag?

B4X:
Sub BtCamera_Click
    Log(BtCamera.Tag)
    Starter.Indice = BtCamera.Tag
    StartActivity(Camera)
End Sub

Thanks in advance
 

DonManfred

Expert
Licensed User
Longtime User
If you have multiple buttons of these you neeed to get a reference the one you clicked...

B4X:
Sub BtCamera_Click
dim btn as Button = Sender ' Get Reference
    Log(btn.Tag) ' Use the Button btn
    Starter.Indice = btn.Tag ' use Button btn too
    StartActivity(Camera)
End Sub
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
So quicky¡¡ Thanks DonManfred¡
Reading the forum, I had some clue about Sender, but I didn't know how to handle.

Thanks again
 
Upvote 0
Top