Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private LblCategory As Label
Private ClvCategories As CustomListView
Private CLVHeight As Int 'This will store the original CLV Height
'Dim Size As Int = 4
' Dim Size As Int = 10
End Sub
Public Sub Initialize
' B4XPages.GetManager.LogEvents = True
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
B4XPages.SetTitle(Me, "Main Title")
CLVHeight = ClvCategories.AsView.Height 'Store the original CLV Height
Dim R As Reflector
R.Target = ClvCategories.sv
R.AddEventFilter("ClvVscroll","javafx.scene.input.ScrollEvent.SCROLL")
End Sub
Private Sub ClvVscroll_Filter (E As Event)
' Dim MouseEvent As JavaObject = E
' Dim deltaY As Double = MouseEvent.RunMethod("getDeltaY",Null)
' Log(deltaY)
E.Consume
End Sub
Private Sub CreateButtonCategory (ButtonText As String, Height As Double) As B4XView
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0, 0, 0, 150dip, Height)
#If B4J
p.Color = xui.Color_Transparent
#End If
p.LoadLayout("BtnCategory")
LblCategory.Text = ButtonText
LblCategory.Alignment = "CENTER" 'no effect
Return p
End Sub
Private Sub LblCategory_MouseClicked (EventData As MouseEvent)
Dim lbl As Label = Sender
xui.MsgboxAsync(lbl.Text & " clicked.","Category click event")
End Sub
Private Sub Button1_Click
ClvCategories.Add(CreateButtonCategory("Sample " & ClvCategories.Size, CLVHeight), ClvCategories.Size)
Sleep(10)
ScrollCheck
End Sub
Private Sub Button2_Click
ClvCategories.RemoveAt(ClvCategories.Size - 1)
Sleep(10)
ScrollCheck
End Sub
Private Sub ScrollCheck
Dim CLVWidth As Int
Dim p As Pane
For x = 0 To ClvCategories.Size - 1
p = ClvCategories.GetPanel(x)
CLVWidth = CLVWidth + (p.Width)
Next
Dim sv As ScrollPane = ClvCategories.sv
If CLVWidth > ClvCategories.AsView.Width Then
ClvCategories.Base_Resize(ClvCategories.AsView.Width, ClvCategories.AsView.Height + 18dip)
sv.SetHScrollVisibility("ALWAYS")
Else
ClvCategories.Base_Resize(ClvCategories.AsView.Width, CLVHeight)
sv.SetHScrollVisibility("NEVER")
End If
End Sub