Android Tutorial Custom Expandable ListView

This code is an example of creating an expandable listview using a scrollview.
The layout of each item in the list is created in code and is customizable on a per item basis.
The example is pretty barebones but exhibits purpose.

If people improve on this listview and add more features or make it even more generic, please post back on the forum so the example may evolve.
 

Attachments

  • expandablelv.png
    expandablelv.png
    8.5 KB · Views: 21,032
  • ExpandableListView.zip
    10.3 KB · Views: 4,958

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 :cool:
 

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:
Top