Using this example from @Erel
I am trying to draw on the screen 32 buttons in 4 rows and 8 columns.
In the designer there is only one panel to contain the buttons.
Static Code Modules
Basic4android v1.2 includes a new type of module which is the static code module. Adding a static code module is done by choosing Project - Add New Module - Code Module. Unlike Activities and Services, code modules are not related in any way with Android process life cycle. These are just...
www.b4x.com
I am trying to draw on the screen 32 buttons in 4 rows and 8 columns.
In the designer there is only one panel to contain the buttons.
This is the code:
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private pnlButtons As B4XView
Type btnObj (Text As String, Tag As Object)
End Sub
Private Sub B4XPage_Appear
Dim intCnt As Int = 0
Dim intSize As Int = ButtonSize
For col = 0 To 3
For row = 0 To 7
Dim btnProp As btnObj
btnProp.Initialize
btnProp.Text = col.As (String) & "," & row.As (String)
btnProp.Tag = intCnt
pnlButtons.AddView(ButtonsCreator(btnProp), row * intSize, col * intSize, intSize, intSize)
intCnt = intCnt + 1
Next
Next
End Sub
Private Sub B4XPage_Created (RootMain As B4XView)
Root = RootMain
Root.LoadLayout("MainPage")
End Sub
Private Sub ButtonsCreator(btnProp As btnObj) As Button
Dim b As Button
b.Initialize("btn")
b.Text = btnProp.Text
b.Tag = btnProp.Tag
Return b
End Sub
Private Sub ButtonSize() As Int
Dim intSize As Int = 0
'This is where I should calculate the width and height of the button, according to the width and height of the device the size that suits each button
intSize = 200
Return intSize
End Sub
Private Sub btn_Click
ToastMessageShow(Sender.As (Button).Tag,False)
End Sub
Last edited: