Android Tutorial Custom Expandable ListView

thedesolatesoul

Expert
Licensed User
Longtime User

GMan

Well-Known Member
Licensed User
Longtime User
i worked something out that works fine - a mix from ListView and CustomListView
 

maleche

Active Member
Licensed User
Longtime User
GMan, anychance you can post an image of your layout so i can get the concept?
I would appreciate any coding ideas too.
Thanks in advance!
 

T0mee

Member
Licensed User
Longtime User
I used it in my App and recognized it isnt working with Android 5 (the items, parents and childs, got no text - just empty lines). On my Android4 device everything is working well. Anybody else got this problem?
 

thedesolatesoul

Expert
Licensed User
Longtime User
I used it in my App and recognized it isnt working with Android 5 (the items, parents and childs, got no text - just empty lines). On my Android4 device everything is working well. Anybody else got this problem?
Maybe its an issue with the label sizes.
 

hookshy

Well-Known Member
Licensed User
Longtime User
It looks nice and it is helpful for doing tutorials and showing functions of the app structured in an expandable list
 

manolis

Member
Licensed User
Longtime User
An improvement for faster expand/collapse operation (Custom Expandable ListView)

It is achieved by adding to the ExpListViewItem type the constructed panel.

B4X:
Type ExpListViewItem(IsParent As Boolean, Expanded As Boolean, label As String, id As Int, childto As Int, p As Panel)

So, instead of to reconstruct all the list for every expand/collapse click event, it is only needed to construct the non initialized panels as this is explained below.

B4X:
Sub DrawListView
    For i = SV.Panel.NumberOfViews-1 To 0 Step -1
        SV.Panel.RemoveViewAt(i)
    Next
    Dim ItemHeight As Int
    ItemHeight = 40dip
    Dim ChildOffset As Int
    ChildOffset = 0dip
    Dim pHeight As Int
    pHeight = 0

    For i = 0 To ExpandableList.Size-1
        Dim item As ExpListViewItem
        item = ExpandableList.Get(i)
        If item.IsParent = True Then
            If item.p.IsInitialized Then
                SV.Panel.AddView(item.p,0,pHeight,100%x,ItemHeight)
            Else
                item.p.Initialize("pnl")
                SV.Panel.AddView(item.p,0,pHeight,100%x,ItemHeight)
                ConstructPanel(item,item.p)
            End If
            pHeight = pHeight + ItemHeight
        End If
        If item.Expanded=True Then
            For j = 0 To ExpandableList.Size-1
                Dim childitem As ExpListViewItem
                childitem = ExpandableList.Get(j)
                If childitem.childto = item.id Then
                    If childitem.p.IsInitialized Then
                        SV.Panel.AddView(childitem.p,ChildOffset,pHeight,100%x-ChildOffset ,ItemHeight)
                    Else
                        childitem.p.Initialize("pnl")
                        SV.Panel.AddView(childitem.p,ChildOffset,pHeight,100%x-ChildOffset ,ItemHeight)
                        ConstructPanel(childitem,childitem.p)
                    End If
                    pHeight = pHeight + ItemHeight
                End If
            Next
        End If
    Next
    SV.Panel.Height = pHeight
End Sub
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…