Android Question RemoveView ... delete the view ?

Discussion in 'Android Questions' started by pierrem, Apr 3, 2015.

  1. pierrem

    pierrem Member Licensed 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
     

    Attached Files:

    Last edited: Apr 3, 2015
  2. klaus

    klaus Expert Licensed User

    What exactly do you want to do ?
    Why do you want to move a view from Panel1 to Panel2, what's the purpose ?
     
    DonManfred and NJDude like this.
  3. Peter Simpson

    Peter Simpson Expert Licensed User

    Hello @pierrem,
    Code:
    Sub bt1_click
        ivTest2.Bitmap = ivTest1.Bitmap
    End Sub
     
    DonManfred likes this.
  4. pierrem

    pierrem Member Licensed User

    Peter,
    OK,thank you it works
    :)

    I change your code for this :
    Code:
    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.
     
  5. klaus

    klaus Expert Licensed User

    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.

    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: Apr 5, 2015
    NJDude likes this.
Loading...
  1. 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.
    Dismiss Notice