Thank you Erel for your reply. I know I could assign it to a Global variable, but there are times that I don’t want to Re-Dim a ScrollView on rotate. Things would work if I could assign it as a Process_Globals variable, but you can't access an activity object from Sub Process_Globals.
I can resolve the issue by making a few code changes, but was wondering if there was a simple way to clear a ScrollView Dim’d in a Sub. Now I can stop wondering!
You can loop through the views until you find the scrollview (if you have more than one then use the tag property to differentiate), then you can clear it.
Look at Activity.GetView and Activity.NumberOfViews, and indeed the upcoming For Each feature.
You can loop through the views until you find the scrollview (if you have more than one then use the tag property to differentiate), then you can clear it.
Look at Activity.GetView and Activity.NumberOfViews, and indeed the upcoming For Each feature.
Thank you kickaha for your reply. Would something like the code below work for me? I take it that the For Each feature will be included in a future release of B4A.
Best regards
B4X:
Sub ClearScrollView
For i = 0 To Activity.NumberOfViews - 1
If Activity.GetView(i) Is ScrollView Then
Activity.GetView(i).RemoveView
End If
Next
End Sub
Thank you kickaha for your reply. Would something like the code below work for me? I take it that the For Each feature will be included in a future release of B4A.
Best regards
B4X:
Sub ClearScrollView
For i = 0 To Activity.NumberOfViews - 1
If Activity.GetView(i) Is ScrollView Then
Activity.GetView(i).RemoveView
End If
Next
End Sub
You should add an Exit after the RemoveView. Continuing to loop is not necessary once the ScrollView is removed.
And you should always check the views in the reverse order because of "Activity.NumberOfViews - 1".
As stated above there is no need to continue the loop once you have removed the view, so you coould add a RETURN after the RemoveView.
The reason you would loop in reverse is that when you delete a view all the higher numbered views are shifted down one and your loop exit condition is now set at more than the number of views.
As stated above there is no need to continue the loop once you have removed the view, so you coould add a RETURN after the RemoveView.
The reason you would loop in reverse is that when you delete a view all the higher numbered views are shifted down one and your loop exit condition is now set at more than the number of views.
@ kickaha & Informatix - Thank you both very much for the informative explanations. Your suggested code below works very well.
Best regards
B4X:
Sub ClearScrollView
For i = Activity.NumberOfViews - 1 To 0 Step - 1
If Activity.GetView(i) Is ScrollView Then
Activity.GetView(i).RemoveView
Return
End If
Next
End Sub
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.