hi, I wrote some code and I do not understand why some of the buttons does not throw an event when clicked
when press the buttons in the array nothing happen, when pressing the panel (empty space) a text edit and button will appear and when pressing that button it will work
:sign0163:
when press the buttons in the array nothing happen, when pressing the panel (empty space) a text edit and button will appear and when pressing that button it will work
:sign0163:
B4X:
#Region Module Attributes
#FullScreen: True
#IncludeTitle: True
#ApplicationLabel: Covert Communication
#VersionCode: 1
#VersionName: 1.0
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: True
#End Region
'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
'Dim pws As PhoneWakeState
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 pp As Panel
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
test_UI
End Sub
Sub Activity_Resume
'pws.KeepAlive(False)
'test_UI
End Sub
Sub Activity_Pause (UserClosed As Boolean)
'pws.ReleaseKeepAlive ' should I do this here, or prevent app from exit (unless press back twice or something like that)
' what happne when usr press home (in the above scenario)
End Sub
Sub test_UI
Dim p As Panel
p.Initialize("p")
Dim btn(50) As Button
If Not (p.IsInitialized) Then
Log ("cant init p")
Else
Log ("p is init already, add button")
For i = 0 To btn.Length -1
If (1 = 0) Then
btn(i).Initialize("btn pressed0")
Else
btn(i).Initialize("btn pressed")
End If
btn(i).Text = i
btn(i).Tag = i
Dim w As Int = 65
Dim h As Int = 55
Dim x As Int = (i*(w+5)) Mod (100%x-w)
Dim y As Int = (Floor((i*(w+5)) / (100%x-w)) * (h+5))
Log ("adding btn " & i & " at " & x & "," & y)
p.AddView(btn(i),x,y,w,h)
Next
Activity.AddView(p,0,0,100%x,100%y)
End If
End Sub
Sub p_Click
Log ("Panel was pressed!")
pp.Initialize("")
Dim edt As EditText
edt.Initialize("")
edt.Text = ""
pp.AddView(edt,100%x/2-100,100%y/2-70,200,70)
Dim btn As Button
btn.Initialize("ok")
btn.Text = "ok"
pp.AddView(btn,100%x/2-100,100,100,60)
Activity.AddView(pp,0,0,100%x,100%y)
End Sub
Sub ok_Click
Log ("ok button was pressed")
pp.RemoveView
End Sub
Sub btn_pressed0_Click
Log ("button0 was pressed")
End Sub
Sub btn_pressed_Click
Log ("button was pressed")
Dim btn As Button
btn = Sender
Log ("button:" & btn.Tag)
ToastMessageShow("pressed", False)
End Sub