Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private xui As XUI
Private Button1 As B4XView
Private Label1 As B4XView
Dim tmrCountdown As Timer 'Timer control
Dim tmrSeconds As Int 'Countdown variable
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Layout1")
MainForm.Show
tmrCountdown.Initialize("tmr",1000) 'Initialise the timer to tick every 1 second
tmrCountdown.Enabled=False 'Timers are initialised as enabled = false anyway but I like things to be very obvious
End Sub
Sub Button1_Click
tmrSeconds=30 'Whatever you are counting down from
tmrCountdown.Enabled = True 'Turn on the timer
End Sub
Sub tmr_tick
tmrSeconds=tmrSeconds-1 'Reduce the countdown every time it ticks
Label1.Text= tmrSeconds 'Display current value on the label
If tmrSeconds=0 Then tmrCountdown.Enabled=False 'Turn off the timer when we hit 0
End Sub