Android Question Should not Activity.RemoveViewAt() "de-initialize" a view ?

MitchBu

Well-Known Member
Licensed User
I found it more convenient to switch layouts by hiding and showing panels, which support all the views. That way, display is instant between layouts.

Before displaying a layout, I test if the panel has been intialized, and if not, then I add the layout to activity.

That worked just fine, until I used CC2 to pick pictures. For some reason, if I go to pick a picture, and simply cancel with the Back button, I do not find the layout I went from. All I see is the plain color of the empty activity.

I then tried to test if the panel was still initialized, and it was, but no way to show it, or bring it to front. It seems to be gone, but still shows initialized.

I then used RemoveAllViews, and loaded again the layout.

But when I go to another layout previously initialized, although all views have been removed, its panel still shows as initialized.

Should it not show as not initialized, since it has been removed ?
 

MitchBu

Well-Known Member
Licensed User
B4X:
Sub RemoveAllViews
    Dim i As Int   
    For i = Activity.NumberOfViews - 1 To 0 Step -1
        Activity.RemoveViewAt(i)
    Next
End Sub

Hi Agraham,

I understand a panel does not have to contain views.

But in this instance, I remove all views from activity with the code above.

After a view has been removed, should it not show as not activated ?
 
Upvote 0

agraham

Expert
Licensed User
I remove all views from activity with the code above.
Ah, your first post implies that you were using Panel.RemoveAllViews. Why are you not using Activity.RemoveAllViews?

After a view has been removed, should it not show as not activated ?
No, it is just removed from it's parent, you are obviously keeping a reference to the panel so it remains in existence, still initialised, and available to reassign to another parent.
 
Upvote 0

MitchBu

Well-Known Member
Licensed User
Ah, your first post implies that you were using Panel.RemoveAllViews. Why are you not using Activity.RemoveAllViews?

No, it is just removed from it's parent, you are obviously keeping a reference to the panel so it remains in existence, still initialised, and available to reassign to another parent.

I shall modify my code, then.


Ah, your first post implies that you were using Panel.RemoveAllViews. Why are you not using Activity.RemoveAllViews?

No, it is just removed from it's parent, you are obviously keeping a reference to the panel so it remains in existence, still initialised, and available to reassign to another parent.

Ah. I see. So I need to experiment about it.

Thank you, Agraham.
 
Upvote 0

MitchBu

Well-Known Member
Licensed User
I found out that under some circumstances, activity seemed to "lose" the layout.

Now I test if indeed the panel has activity as parent, and if not, I attach it again with activity.addview.

Problem solved :)

Thank you, Agraham.
 
Upvote 0
Top