Hi to all. The idea is to programmatically create a UI, without using the Designer. There are no problems about positioning the various views.. but what I miss is how to set the events. I mean: in the Designer we have the "Tools/Generate Members" take creates the appropriate code for the allowed events, but I don't see (programmatically) either how to set up more that an event in the Initialize function, or how to add appropriate code for event triggering. I did the attached "experiment", with a Label, adding it to activity and creating a Click event that.. of course .. doesn't work...
Thanks for your attention
Thanks for your attention
B4X:
#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Type Controllo(Name As String, _ ' this structure contains some definitions to set up a view
Type As Byte, _
X As Int, Y As Int, Wid As Int,Hei As Int, _
Col As Long, _
Eve As Byte, _
Txt As String, _
Ena As Boolean, _
Vis As Boolean, _
Tcol As Long, _
Gra As Byte)
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.
Private ETIC,INPUT,LISTA As Byte
Private CLICK As Byte
Private LEFT,RIGHT,CENTER,TOP,BOTTOM,CENTERH,CENTERV As Byte
Private NewLab As Label
Private NewInp As EditText
Private NewLis As ListView
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")
ETIC=0 : INPUT=1: LISTA=2 ' ONLY ETIC, namely Label is used
CLICK=0
LEFT=0 : RIGHT=1 : CENTER =2 : CENTERH=3 : CENTERV=4
TOP=0 : BOTTOM=1
AutoTest
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
'------------------------------------------------------------------
'
'-------------------------------------------------------------------
Private Sub AutoTest
Dim Test As Controllo
Test.Col=Colors.Green
Test.Ena=True
Test.Eve=CLICK
Test.Hei=200
Test.Wid=400
Test.Name="LabelTest"
Test.Type=ETIC
Test.Txt="Prova"
Test.Vis=True
Test.X=10
Test.Y=30
Test.Gra=CENTERH
Test.Tcol=Colors.Black
ControlPositioning(Activity,Test)
End Sub
Private Sub ControlPositioning(Parent As Panel,Vw As Controllo)
Private event As String
Private W,H As Int
Private fx,fy As Float
W=Parent.Width
H=Parent.Height
fx=W*0.01*Vw.X
fy=H*0.01*Vw.Y
Select Vw.eve ' should be the EVENT
Case CLICK
event=Vw.Name & "_" & "Click"
End Select
Select Vw.Type ' only ETIC
Case ETIC
NewLab.Initialize(event)
' ADDED to "Parent", but Parent is Activity
Parent.AddView(NewLab,Round(fx),Round(fy),Vw.Wid,Vw.Hei)
NewLab.Color=Vw.Col
NewLab.Enabled=Vw.Ena
NewLab.Visible=Vw.Vis
NewLab.Text=Vw.Txt
NewLab.TextColor=Vw.Tcol
Select Vw.Gra
Case LEFT
NewLab.Gravity=Gravity.LEFT
Case RIGHT
NewLab.Gravity=Gravity.RIGHT
Case CENTER
NewLab.Gravity=Gravity.CENTER
Case CENTERH
NewLab.Gravity=Gravity.CENTER_HORIZONTAL
Case CENTERV
NewLab.Gravity=Gravity.CENTER_VERTICAL
Case TOP
NewLab.Gravity=Gravity.TOP
Case BOTTOM
NewLab.Gravity=Gravity.BOTTOM
End Select
Case INPUT
Case LISTA
End Select
End Sub
private Sub LabelTest_Click
Dim a,b As Int
b=3 ' dummy code for debug purposes
a=b
End Sub