Button not active

cstangor

Member
Licensed User
Longtime User
Sorry, but I'm having trouble with something basic here.

If I put a a panel on an activity and a button on the panel, the button event fires when the orientation is changed but not when the button is pressed???

Thanks

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   
   Dim Button1 As Button
   Dim Panel1 As Panel

End Sub

Sub Activity_Create(FirstTime As Boolean)
   Panel1.Initialize(Null)
   Activity.AddView(Panel1, 0, 0, 100%x ,100%y)
   Button1.Initialize(Button1_Click)
   Button1.Text = "OK"
   Panel1.AddView(Button1, 0, 0, 100, 100)
End Sub
Sub Button1_Click
   Log ("Button1 Clicked")
End Sub
 

NJDude

Expert
Licensed User
Longtime User
You have some problems:
B4X:
Panel1.Initialize(Null) '<--- WRONG

Panel1.Initialize("") '<--- Right

Button1.Initialize(Button1_Click) '<--- WRONG

Button1.Initialize("Button1") '<--- Right
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
To follow up on NJDude's advice, if you want the button clicked right off the bat here is the code. It will do what you intend:

B4X:
Dim Button1 As Button    
Dim Panel1 As Panel

Sub Activity_Create(FirstTime As Boolean)
    Panel1.Initialize("")
    Activity.AddView(Panel1, 0, 0, 100%x ,100%y)
    Button1.Initialize("Button1")
    Button1.Text = "OK"
    Panel1.AddView(Button1, 0, 0, 100, 100)
    Button1_Click
End Sub

Sub Button1_Click
   Msgbox("Button1 Clicked","")
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…