Android Question RemoveView ... delete the view ?

pierrem

Member
Licensed User
Longtime User
Hi,

Problem to 'swap' a view from a Panel to another ...
There is something I misunderstand !
But don't know what

Very simple project in attachment.

If someone (very patient, I'm sure it's obvious) could help

Thks in advance
and Happy Easter

PS : initially, my need is to avoid this message (from another project) :

java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

I've read some post about GetParent and setParent, it doesn't help me
 

Attachments

  • example1.zip
    20.5 KB · Views: 230
Last edited:

pierrem

Member
Licensed User
Longtime User
Peter,
OK,thank you it works
:)

I change your code for this :
B4X:
Sub bt1_click
    If state = 0 Then
        state=1
        ivTest2.Bitmap=ivTest1.Bitmap
        ivTest1.Bitmap=Null
    Else
        state=0
        ivTest1.Bitmap=ivTest2.Bitmap
        ivTest2.Bitmap=Null
    End If
    Log("clic OK")
End Sub

Klaus,
Originally, the imageview are stored in a map and I want to display them on one panel or another one ...
Not interest at all, just keeping to learn

But ... I still misunderstand why
I have to 'swap' the iv.bitmap and not the iv itself

I guess that if I .remove the imageview from its parent, then I'll be able to 'affect' (=) it to another parent.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Originally, the imageview are stored in a map and I want to display them on one panel or another one ...
The reason of my question was to know exactly what you want to.
Depending on the answer the code might be quite different.
If you want to dispaly one ImageView or another you should consider playing only with the Visible property set to True or False.
But this depends of course on the other data you want to display.

I guess that if I remove the imageview from its parent, then I'll be able to 'affect' (=) it to another parent.
No, if you set ivTest2 = ivTest1 this means that both variables point to the same object.
If you remove it, you need to initialize it again and add it onto the new parent view !

So, as Peter Simpson already suggested, changing the bitmap is a good solution.
 
Last edited:
Upvote 0
Top