#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 600
#End Region
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private xui As XUI
Private btn(12),lbl(12) As B4XView
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.Show
createButtonsAndLabels
End Sub
Private Sub createButtonsAndLabels
Dim width=100, height=50 As Float
Dim startX=50, startY=50,x=0, y=0,space=20 As Float
Dim rows As Int = 3
Dim col As Int = btn.Length/rows
For i = 0 To btn.Length-1
x = (width*(i Mod col))+(space*(i Mod col))+startX
y = Floor(i/col)*(height+space)+startY
btn(i) = xui.CreatePanel("btn")
btn(i).SetColorAndBorder(xui.Color_White,1,xui.Color_ARGB(255,91,91,91),5)
lbl(i) = createLabel("")
lbl(i).Text = $"Button${i+1}"$
lbl(i).SetTextAlignment("CENTER","CENTER")
btn(i).AddView(lbl(i),0,0,width,height)
MainForm.RootPane.AddNode(btn(i),x,y,width,height) '<- Change according to B4X IDE (b4a -> Activity.Addview(....))
Next
End Sub
Private Sub createLabel(Event As String) As B4XView
Dim newlbl As Label
newlbl.Initialize(Event)
Return newlbl
End Sub
Private Sub btn_Touch (Action As Int, X As Float, Y As Float)
Dim senderBtn As B4XView = Sender
Select Action
Case 0 'down
senderBtn.Color=xui.Color_ARGB(255,Rnd(0,256),Rnd(0,256),Rnd(0,256))
Case 1 'up
Sleep(200)
senderBtn.Color=xui.Color_White
Case 2 'move
'do nothing
End Select
End Sub