Hi there.
I was experimenting just a few days back with loading a (created by Designer) layout in an activity multiple times.
To test it out i created a simple app (attached):
'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 Label1 As Label
Dim Panel1 As Panel
Dim ScrollView1 As ScrollView
End Sub
Sub Activity_Create(FirstTime As Boolean)
ScrollView1.Initialize(100%y)
Dim i, count, spacing As Int
count=4
spacing=1
For i=0 To count
ScrollView1.Panel.LoadLayout("ScrollViewTemplate")
Panel1.Top=(Panel1.Height+spacing)*i
Panel1.Width=100%x
Panel1.Tag=i
Label1.Text="Is this 'instance #"&i&"' of Label1?"
Next
Activity.AddView(ScrollView1, 0, 0, 100%x, 100%y)
ScrollView1.Panel.Height=(i*Panel1.Height)+(i*spacing)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Panel1_Click
Log("Panel1_Click")
Dim ClickedPanel As Panel
ClickedPanel=Sender
Dim Tag As Int
Tag=ClickedPanel.Tag
Log("Clicked Panel Tag is: "&Tag)
Label1.Text="Label1.Text has now been modified"&CRLF&"Tag of clicked panel is "&Tag
End Sub
ScrollViewTemplate is a layout i created with the Designer (320x480 scale=1 only).
It is a panel that contains an ImageView and a Label.
Loading the layout multiple times works perfectly BUT the global references to each panel and child views are not useable...
As Erel pointed out these references will refer only to the
last instance of the layout loaded.
Look at the Panel1_Click Sub.
When this Sub is called (sometime after Activity_Create has exited), Panel1 will be a reference to the Panel1 instance last loaded by the layout.
The Sub still functions perfectly though and it's Sender object is the clicked Panel in the ScrollView (not always the last Panel loaded by the layout).
In my app i'm creating the ScrollView Panels with data from a List so by setting the Panel Tag to the List index value i can detect which data to act upon in Panel1_Click.
Label1.Text="Label1.Text has now been modified"&CRLF&"Tag of clicked panel is "&Tag
I added that just to confirm what Erel stated
these references will refer only to the last instance of the layout loaded - look at the last Panel text in the ScrollView when you click any ScrollView Panel.
Oh for some javascript and it's anonymous function closures :sign0162:!
Martin.