You can declare a class that takes care of the common layout elements, by code or loading it. Each activity declares an instance of that class and initializes it passing itself or a Panel (as a parameter) where the layout will be loaded.
The common elements and events will be declared in that class. Then each activity will have a class instance for that part of UI, and you will only need to write the event once, in the class
v.Initialize(Me)
javac 1.8.0_111
src\b4a\example\classview\ikinci.java:346: error: incompatible types: Class<CAP#1> cannot be converted to BALayout
mostCurrent._v._initialize(null,mostCurrent.activityBA,(anywheresoftware.b4a.objects.ActivityWrapper) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.ActivityWrapper(), (anywheresoftware.b4a.BALayout)(ikinci.getObject())));
^
where CAP#1 is a fresh type-variable:
CAP#1 extends Object from capture of ?
Nevertheless you MUST catch the event in each an every activity, or it will not fire at all.
What you can do is to have a simple line inside every event to call a sub in a code module... Keep in mind, however, that a code module cannot interact with the GUI directly!
You can declare a class that takes care of the common layout elements, by code or loading it. Each activity declares an instance of that class and initializes it passing itself or a Panel (as a parameter) where the layout will be loaded.
The common elements and events will be declared in that class. Then each activity will have a class instance for that part of UI, and you will only need to write the event once, in the class
Ok. Its just runned. Cannot load layout to activity but in a panel. I just need to make one layout file more.
Thank you
Here is Codes
Class :
B4X:
Sub Class_Globals
Dim a As Object
Dim p As Panel
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize (activity As Object, panel As Panel)
a = activity
p = panel
End Sub
public Sub loadLayout(layoutfile As String)
p.LoadLayout(layoutfile)
End Sub
Sub Button1_Click
Log("button 1 click")
End Sub
Sub Button2_Click
CallSubDelayed(a,"Button2_Click")
End Sub
Main :
B4X:
Sub Process_Globals
End Sub
Sub Globals
Dim v As viewClass
Private container As Panel
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("container")
v.Initialize(Me,container)
v.loadLayout("1")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button2_Click
StartActivity(ikinci)
End Sub
Activity 2 :
B4X:
Sub Process_Globals
End Sub
Sub Globals
Dim v As viewClass
Private container As Panel
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("container")
v.Initialize(Me,container)
v.loadLayout("2")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub