iOS Question Mutli Stacked Customlistviews

db0070

Active Member
Licensed User
I have been trying to solve this for a while.
I have 6 customlistviews all stacked up on top of each other - each customlistview can have 10 or more labels. A slider selects which of the 6 customlistview is under focus. How best I can determine which label was clicked from which customlistview?
My code that creates the customlistview is something like this:
B4X:
for i = 0 to 9
    clv1.Add(CreateListItem("Tone" & i, "clv1_ItemClick",i,clv1.GetBase.Width, 50dip),i)
next

for i = 0 to 9
    clv2.Add(CreateListItem("Tone" & i, "clv2_ItemClick",i,clv2.GetBase.Width, 50dip),i)
next
....

Sub CreateListItem(Text As String, s As String, position As Int, Width As Int, Height As Int) As Panel
    Dim p As Panel
    p.Initialize("")
    p.SetLayoutAnimated(0, 1, 0, 0, Width, Height) 'set the size before the layout is loaded
    p.LoadLayout("almBtnLayout") 'almBtnLayout has a label and imageview both same size and on top of each other
    label1.Text = Text
    ImageView1.Tag = s & " (" & position & ",)"  'trying to use tags to determine which is clicked
    myLabel.Tag = ImageView1.Tag
    Return p
End Sub

Sub ImageView1_Click
'this my attempt to call the customlistview click event
'this looks ugly, must be better way, and besides it does not work!!!
'trying to work out first which customlistview then which item in the customlistview
    Dim t1 As ImageView    = Sender
    Dim a1 As String = t1.Tag 'expecting the tag to be something like clv1_ItemClick (clv1, 0)
    Dim i As Int
    If i > 0 Then
        i = a1.IndexOf("(")
        Dim i2 As Int = a1.IndexOf2(",",i)
        If i2 > i Then
            Dim s1 As String = a1.SubString2(0,i-1)
            Dim s2 As String = a1.SubString2(i+1,i2)
            CallSubDelayed3(Me,s1,s2,0)  'Trying to call clvx_ItemClick
        End If
    End If 
End Sub
 
Last edited:

Erel

Administrator
Staff member
Licensed User
I'm not exactly sure what you are doing however there is no reason to make it so complicated. Create a custom type with all the information you want to hold and set the tag property to be an instance of that type.
 
Top