Wanted to create a very basic tree view menu in B4A, but since I could not find a B4A equivalent for the B4J TreeView and as I already use CLVExpandable and BBlistitem in my app, it seemed logical to use Erel's BCTexInCLV.
For some reason the first bloc is blanc (see picture), but the text is there since clicking on a line shows the corresponding link.
Does anyone know why?
Many thanks in advance for your help,
john m.
MainPage:
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region
'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private CustomListView1 As CustomListView
Private TextEngine As BCTextEngine
Private BBListItemIndexInItems As Int = 0
Private Expandable As CLVExpandable
Private bc As BitmapCreator
Private thema(5) As String
Private SP() As String
Private CLVpanel As B4XView
End Sub
Public Sub Initialize
' B4XPages.GetManager.LogEvents = True
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
If Root.Width = 0 Then
Wait For B4XPage_Resize (Width As Int, Height As Int)
End If
Root.LoadLayout("MainPage")
CLVpanel.top = 100dip
CLVpanel.left=40%x
CLVpanel.width=50%x
TextEngine.Initialize(Root)
Expandable.Initialize(CustomListView1)
thema(0) = "Animals,Antilope,Bear,Dolfin,Elephant,Horse"
thema(1) = "Boys,Banjamin,Cesar,Napoleon"
thema(2) = "Cities,Berlin,Chicago,Rome,Zürich"
thema(3) = "Girls,Jennifer,Sophia,Vanessa"
thema(4) = "Vehicles,Cars,Steam engines,Tractors,Velos"
Dim pnl As B4XView = xui.CreatePanel("")
pnl.SetLayoutAnimated(0, 0, 0, CustomListView1.AsView.Width-100dip, 100dip)
pnl.LoadLayout("Item")
For i = 1 To 5
Dim pnl As B4XView = xui.CreatePanel("")
pnl.SetLayoutAnimated(0, 0, 0, CustomListView1.AsView.Width-100dip, 100dip)
pnl.LoadLayout("Item")
Dim TitlePnl As B4XView = pnl.GetView(0)
SP = Regex.Split(",",thema(i-1))
TitlePnl.GetView(0).Text= SP(0) '$"This is item n° ${i}"$
Dim BB As BBListItem = pnl.GetView(1).GetView(BBListItemIndexInItems).Tag
BB.TextEngine = TextEngine
BB.Text = CreateItemText(i)
Dim ex As ExpandableItemData = Expandable.CreateValue(pnl, "not used")
ex.CollapsedHeight = 30dip
ex.ExpandedHeight = Max(ex.CollapsedHeight, BB.mBase.Height + 00dip + TitlePnl.Height)
Dim arrow As B4XView = pnl.GetView(0).GetView(1)
If ex.ExpandedHeight > ex.CollapsedHeight Then
arrow.Visible = True
Else
arrow.Visible = False
End If
pnl.SetLayoutAnimated(0, 0, 0, pnl.Width, ex.CollapsedHeight)
CustomListView1.Add(pnl, ex)
Next
CustomListView1_ScrollChanged(0)
End Sub
Private Sub CreateItemText(index As Int) As String
Dim sb As StringBuilder
sb.Initialize
' sb.Append($"[alignment=center][b]Item #${index}[/b][/alignment]"$)
For j = 1 To SP.Length-1
sb.Append(CRLF).Append($"[url=${SP(0)}+${SP(j)}]${SP(j)}[/url]"$)
Next
Return sb.ToString
End Sub
Private Sub BBListItem1_LinkClicked (URL As String)
Dim bb As BBListItem = Sender
Dim index As Int = CustomListView1.GetItemFromView(bb.mBase)
Log("link clicked("&index&"): "&URL)
End Sub
Private Sub CustomListView1_ScrollChanged (Offset As Int)
For i = 1 To CustomListView1.Size - 1
Dim pnl As B4XView = CustomListView1.GetPanel(i)
If pnl.NumberOfViews = 0 Then Return
Dim BB As BBListItem = pnl.GetView(1).GetView(BBListItemIndexInItems).Tag
BB.ParentScrolled(Offset, CustomListView1.GetRawListItem(i).Offset, CustomListView1.AsView.Height, pnl.GetView(0).Height)
Next
End Sub
#if B4i or B4A
Private Sub pnlTitle_Click
#Else If B4J
Private Sub pnlTitle_MouseClicked (EventData As MouseEvent)
#End If
Dim index As Int = CustomListView1.GetItemFromView(Sender)
Dim e As ExpandableItemData = Expandable.ToggleItem(index)
CustomListView1_ScrollChanged(CustomListView1.sv.ScrollViewOffsetY)
End Sub
Sub BBCodeView1_LinkClicked (URL As String)
Log("link clicked: "&URL)
End Sub