Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private timer1 As Timer
Private seconds As Int = 59
' Component variables
Private myCountdown As B4XDaisyCountdown
Private secItem As B4XDaisyCountdownItem
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.Color = xui.Color_RGB(245, 247, 250) ' Light background [6]
' 1. Initialize the main countdown container
myCountdown.Initialize(Me, "myCountdown") [3]
' Set properties like orientation and gap spacing
myCountdown.setOrientation("horizontal") [7]
myCountdown.setGap("gap-4") [7]
Dim pnlCountdown As B4XView = myCountdown.CreateView(300dip, 100dip) [8]
Root.AddView(pnlCountdown, 20dip, 50dip, 300dip, 100dip)
' 2. Initialize a seconds item
secItem.Initialize(Me, "secItem") [9]
secItem.Value = seconds [10]
secItem.Digits = 2 ' Force 2-digit format (e.g. 09) [2]
secItem.Label = "sec" [2]
secItem.LabelPosition = "BOTTOM" [2]
secItem.Variant = "primary" ' Use semantic DaisyUI colors [2]
secItem.TextSize = "text-4xl" [2]
' Add the item to the countdown container
myCountdown.AddItem(secItem) [11]
' 3. Start the timer to update the value
timer1.Initialize("timer1", 1000)
timer1.Enabled = True
End Sub
Private Sub timer1_Tick
seconds = seconds - 1
If seconds < 0 Then seconds = 59
' Update the item's value dynamically
secItem.Value = seconds [10]
End Sub