B4A Library CLVNested - Allows nesting CLVs

firefox_e9gvxSKgTH.png


Putting a CLV inside another one will not work out of the box. The inner list will not be scrollable.

CLVNested makes it possible.

Limitations:

- One list per item.
- The user will not be able to interact with views added to the inner list. The basic features of the inner list will work.
- Will not work with other extensions that "steal" the touch events such as CLVSwipe.

Usage:

1. Initialize the CLVNested object.
2. Load the layout with the main list to nested.base.
3. Set the main list with:
B4X:
nested.CLV = CustomListView

4. Add the items. If you want to add items with inner lists then you need to set the panel's tag to point to the list.

Complete example:
B4X:
Sub Globals
   Private CustomListView1 As CustomListView
   Private clvItem As CustomListView
   Private xui As XUI
   Private nested As CLVNested
End Sub

Sub Activity_Create(FirstTime As Boolean)
   nested.Initialize(Activity)
   nested.base.LoadLayout("1")
   nested.CLV = CustomListView1
   For i = 1 To 10
       CustomListView1.AddTextItem($"*** TITLE (${i}) ***"$, "")
       Dim p As B4XView = xui.CreatePanel("")
       p.SetLayoutAnimated(0, 0, 0, 100%x, 200dip)
       p.LoadLayout("Item")
       p.Tag = clvItem 'must set the Panel tag like this
       FillInnerList
       CustomListView1.Add(p, "")
   Next
End Sub

Sub FillInnerList
   For x = 1 To 10
       clvItem.AddTextItem($"Item #${x}"$, x)
   Next
End Sub

Depends on ViewsEx library.

Note that such solution is not required in B4i or B4J. The standard xCLV will suffice.

Updates

v1.10 - Adds support for nested horizontal CLVs.
 

Attachments

  • CLVNested.zip
    12.7 KB · Views: 912
Last edited:

Daniel44

Active Member
Licensed User
firefox_e9gvxSKgTH.png


Putting a CLV inside another one will not work out of the box. The inner list will not be scrollable.

CLVNested makes it possible.

Limitations:

- One list per item.
- The user will not be able to interact with the inner list views.
- Will not work with other extensions that "steal" the touch events such as CLVSwipe.

Usage:

1. Initialize the CLVNested object.
2. Load the layout with the main list to nested.base.
3. Set the main list with:
B4X:
nested.CLV = CustomListView

4. Add the items. If you want to add items with inner lists then you need to set the panel's tag to point to the list.

Complete example:
B4X:
Sub Globals
   Private CustomListView1 As CustomListView
   Private clvItem As CustomListView
   Private xui As XUI
   Private nested As CLVNested
End Sub

Sub Activity_Create(FirstTime As Boolean)
   nested.Initialize(Activity)
   nested.base.LoadLayout("1")
   nested.CLV = CustomListView1
   For i = 1 To 10
       CustomListView1.AddTextItem($"*** TITLE (${i}) ***"$, "")
       Dim p As B4XView = xui.CreatePanel("")
       p.SetLayoutAnimated(0, 0, 0, 100%x, 200dip)
       p.LoadLayout("Item")
       p.Tag = clvItem 'must set the Panel tag like this
       FillInnerList
       CustomListView1.Add(p, "")
   Next
End Sub

Sub FillInnerList
   For x = 1 To 10
       clvItem.AddTextItem($"Item #${x}"$, x)
   Next
End Sub

Depends on ViewsEx library.

Note that such solution is not required in B4i or B4J. The standard xCLV will suffice.

Updates

v1.10 - Adds support for nested horizontal CLVs.

Hi Erel. I'm trying to implement this project but with a sqlite db. My db has countries and their important cities. I don't know how to do it. I'd like where Title is the Country Name and then where the items are their cities. How can I do that? Thank you.
 

mangojack

Expert
Licensed User
Longtime User
@Daniel44 ... Please start a new thread for this question . Do so and I will try to supply a Example.

@Erel ... Again you might want to remove these posts. It is being handled in another thread.
 
Last edited:
Top