Click Event doesn't work with array of buttons

Johnmcenroy

Active Member
Licensed User
Longtime User
Hello
This is a code from beginners guide:

B4X:
Sub Process_Globals
End Sub

Sub Globals
 Dim Buttons() As Button
 Dim b1 As Button
 Dim b2 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
 Activity.LoadLayout ("1.bal")
 Buttons = Array As Button(b1, b2)
End Sub

Sub Buttons_Click
 Dim btn As Button
 btn = Sender
 Activity.Title = "Button " & btn.Tag & " clicked"
End Sub

I made two buttons b1 and b2 in designer.
It doesn't work. Why ?

When buttons are initialized in code NOT in designer all works fine.
 
Last edited:

jafuve

Member
but I'm creating the buttons by code!!
Example:
Dim bntB (3) as button

For j = 0 To 3- 1
bntB(j).Initialize("bntB")
bntB(j).Text = ". . ."
scv.Panel.AddView(bntB(j),lwidth+10dip,i*50dip+2dip,ewidth,50dip)
Next

Sub bntB_Click
Dim btn As Button
btn = Sender
Msgbox("Button " & btn.Tag & " clicked","This")
End Sub

and the Sub bntB_Click event doesn´t work!!
what can I do??
 
Upvote 0
Top