Well after much searching i came to the same conclusion as many other developers - the parameter that defines whether the views are looped in a continuous cycle can only be set if the StackView is defined using an XML layout file.
It seems there is no method to tell the StackView to loop through all views if the StackView is created in code.
So i've created a new method:
Initialize2(EventName As String, LayoutName As String)
An XML layout file named
my_stack_view.xml has been created and saved in the Objects\res\layout folder:
<StackView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateFirstView="true"
android:animateLayoutChanges="false"
android:loopViews="true">
</StackView>
Just needed to comment out the previous Initialize method and add the new Initialize2 method:
' StackView1.Initialize("StackView1")
StackView1.Initialize2("StackView1", "my_stack_view")
And it works as expected.
I did set android:animateLayoutChanges to "true" and found that the animation on a low power ICS tablet was stuttering, so i changed the attribute to "false".
Then i updated the Sub StackView1_GetView:
Sub StackView1_GetView(Panel1 As Panel, Position As Int) As Panel
Log("StackView1_GetView")
Log(Panel1)
Dim Label1 As Label
If Panel1.IsInitialized=False Then
Log("Initializing new Panel")
Panel1.Initialize("")
Panel1.Color=Colors.Gray
Label1.Initialize("")
Label1.Color=Colors.White
Label1.TextColor=Colors.Black
Panel1.AddView(Label1, 10dip, 10dip, 240dip, 120dip)
Else
Log("Recycling Panel") ' never gets logged
Label1=Panel1.GetView(0)
End If
Label1.Text="This is StackView item #"&Position
Return Panel1
End Sub
The previous Sub was not re-using the Label on a recycled Panel, instead it was always adding a new Label (on top of the old Label).
That's the theory - in practice looking at the log i have not seen a Panel being recycled once.
Each time the StackView call's it's getView method it does not pass an existing view to that method to be recycled.
Increasing the number of 'DisplayedChild' from 5 to 25 did not cause any recycling of views.
If the StackView is not going to attempt to recycle any views then i could make the GetView event Sub so that it does not get passed a view to recycle (and the view is always Null or not initialized) and the Sub could return any type of View instead of being hardcoded to always return a Panel.
The GetView Sub could return a WebView, ImageView or any other type of View - much more flexible.
I'll have a look at the source code and try to establish why this view recycling does not happen before i make any changes to the GetView Sub.
As for using a StackView in a homescreen widget.
I've not worked much with homescreen widgets so had to have a look at the tutorials - the ConfigureHomeWidget command requires the name of a B4A layout file in order to create the widget UI.
So unless a StackView can be added to a B4A layout file it will not be possible to use a StackView in a widget - sounds like i should find the time to read up on the latest B4A updates where a custom View can now be used in the B4A Designer!
BUT i am pushed for time over the next few days so will have to hope Erel or someone else is following this thread and can comment on that.
Martin.