B4J Question event inside expandable customlistview

Chris Guanzon

Active Member
Licensed User
Longtime User
Hi, how can I get the events inside the item?
I generate customlistview click event, but get the same index/value in each row in expandable customlistview.

.
 

Chris Guanzon

Active Member
Licensed User
Longtime User
More information please. Post the code that builds this list.

this is the code I used:

B4X:
For i = 1 To 5
    Dim NumberOfItems As Int = Rnd(1, 20)
    Dim p As B4XView = CreateItem(0xFF262626, "Item #" & i, NumberOfItems * 30dip + 30dip + 20dip)
    clvSidebarMenu.Add(p, expandable.CreateValue(p, "some value"))
    CallSubDelayed3(Me,"SetScrollPaneBackgroundColor", clvSidebarMenu, xui.Color_ARGB(0, 38, 38, 38))
    For j = 1 To NumberOfItems
          clvSidebarSubMenu.Add(CreateScheduleList("subItem #" & j ,clvSidebarSubMenu.AsView.Width, 30dip), j)
          CallSubDelayed3(Me,"SetScrollPaneBackgroundColor", clvSidebarSubMenu, xui.Color_ARGB(0, 20, 20, 20))
    Next
Next
 
Upvote 0

Chris Guanzon

Active Member
Licensed User
Longtime User
I guess that CreateScedulelist loads a layout with a CLV, right? What is its event name?

here's the code of CreateScheduleList:

B4X:
Sub CreateScheduleList(skedTime As String, Width As Int, Height As Int) As Pane
    Dim p As Pane
    p.Initialize("")
    p.SetLayoutAnimated(0, 0, 0, Width, Height)
    p.LoadLayout("sidebar_sub_item")
    
    lblSubItem.Text = skedTime
    Return p
End Sub
 
Upvote 0

rraswisak

Active Member
Licensed User
Longtime User
just my thought, you must set unique value for each sub-menu;

B4X:
    Try
        For i = 1 To 5
            Dim NumberOfItems As Int = Rnd(5, 20)
            Dim p As B4XView = CreateItem(0xFF262626, "Item #" & i, NumberOfItems * 30dip + 30dip + 20dip)
            clvSidebar.Add(p, expandable.CreateValue(p, "some value"))
            
            For j = 1 To NumberOfItems
                CustomListView1.Add(CreateScheduleList("subItem #" & j ,CustomListView1.AsView.Width, 30dip), i*100 + j)
            Next
        Next
    Catch
        Log(LastException)
    End Try

The above code ( i*100 + j) will generate value for each sub menu start by 101, 102... 201,202... etc

You can grab this value here:
B4X:
Private Sub CustomListView1_ItemClick (Index As Int, Value As Object)
    Log("You click menu: " & Value)
End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
    expandable.Initialize(clvSidebar)
    Try
        For i = 1 To 5
            Dim NumberOfItems As Int = Rnd(1, 20)
            Dim p As B4XView = CreateItem(0xFF262626, "Item #" & i, NumberOfItems * 30dip + 30dip + 20dip, i - 1)
            clvSidebar.Add(p, expandable.CreateValue(p, "some value: " & i))
            
            For j = 1 To NumberOfItems
                CustomListView1.Add(CreateScheduleList("subItem #" & j ,CustomListView1.AsView.Width, 30dip), j)
                
            Next
        Next
    Catch
        Log(LastException)
    End Try
    
End Sub

Sub CreateItem(clr As Int, Title As String, ExpandedHeight As Int, ParentIndex As Int) As B4XView
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, clvSidebar.AsView.Width, ExpandedHeight)
    p.LoadLayout("Layout2")
    p.SetLayoutAnimated(0, 0, 0, p.Width, p.GetView(0).Height) 'resize it to the collapsed height
    CustomListView1.AsView.Tag = ParentIndex
    lblTitle.Text = Title
    pnlTitle.Color = clr
    pnlExpanded.Color = ShadeColor(clr)
    Return p
End Sub

Private Sub CustomListView1_ItemClick (Index As Int, Value As Object)
    Dim clv As CustomListView = Sender
    Dim ParentIndex As Int = clv.AsView.Tag
    Dim ParentValue As String = expandable.GetValue(ParentIndex)
    Log(ParentValue)
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…