Android Question Getting data from [B4X] CLVExpandable

Sergey_New

Well-Known Member
Licensed User
Longtime User
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    expandable.Initialize(clv1)
    For i = 1 To 20
        Dim p As B4XView = CreateItem(Rnd(0xFF000000, 0xFFFFFFFF), "Item #" & i, Rnd(100dip, 300dip) + 60dip)
        clv1.Add(p, expandable.CreateValue(p, "value" & i))
    Next
End Sub
Tell me how to get the passed "value" & i on the clv1_ItemClick event?
B4X:
Sub clv1_ItemClick (Index As Int, Value As Object)
    expandable.ToggleItem(Index)
    '???
End Sub
 

stevel05

Expert
Licensed User
Longtime User
Try either:
B4X:
    Log(expandable.GetValue(Index))
    
    'Or
    
    Dim V As ExpandableItemData = Value
    Log(V.Value)
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
I am trying to pass multiple values with:
B4X:
Type PersonData (name As String, sex As String)
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    expandable.Initialize(clv1)
    Dim psd As PersonData
    psd.Initialize
    psd.name="name1"
    psd.sex="M"
    Dim p As B4XView
    p=CreateItem(Rnd(0xFF000000, 0xFFFFFFFF), "ItemM", Rnd(100dip, 300dip) + 60dip)
    clv1.Add(p, expandable.CreateValue(p, psd))
    psd.Initialize
    psd.name="name2"
    psd.sex="F"
    p=CreateItem(Rnd(0xFF000000, 0xFFFFFFFF), "ItemF", Rnd(100dip, 300dip) + 60dip)
    clv1.Add(p, expandable.CreateValue(p, psd))
End Sub
I get the same values for two lines:
B4X:
Sub clv1_ItemClick (Index As Int, Value As Object)
    expandable.ToggleItem(Index)
    Dim V As ExpandableItemData = Value
    Dim psd As PersonData=V.Value
    Log(psd.name)
    Log(psd.sex)
End Sub
How to fix?
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
B4X:
Sub AddItem(Name As String, Sex As String)
    Dim psd As PersonData
    psd.Initialize
    psd.name=Name
    psd.sex=Sex
    Dim p As B4XView
    p=CreateItem(Rnd(0xFF000000, 0xFFFFFFFF), "ItemM", Rnd(100dip, 300dip) + 60dip)
    clv1.Add(p, expandable.CreateValue(p, psd))
End Sub
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
Got it, thank you!
But the first tip worked.
 
Upvote 0
Top