RemoveView Question

pixelpop

Active Member
Licensed User
Longtime User
In my activity, I have a panel created in Designer to which several views are assigned (buttons, labels, etc.). The panel name is pnlDisplay and Activity is its parent. One of the buttons assigned to this panel is called btnSearch. When I click btnSearch, I want to remove the pnlDisplay and replace it with a panel defined in code as pnlSearch. When btnSearch is clicked, I call Activity.RemoveView(pnlDisplay). When I compile this, I get the following compile error:

Error description: Object reference not set to an instance of an object.
Occurred on line: 412
Activity.RemoveView(pnlDisplay)
Word: (

Where have I gone off track?
 

grant1842

Active Member
Licensed User
Longtime User
Try using pnlDisplay.RemoveView

It removes itself from whatever parent it is assigned to. If your layout isn't too complicated I would agree with NJDude about simply turning on and off the visibility of Views.
 
Upvote 0

pixelpop

Active Member
Licensed User
Longtime User
Turning off visibility worked great! Thanks.

On a side note, what would be the circumstances when removing a view would be a better option than using the visibility property? For instance, are more resources consumed by continually hiding/showing a view versus removing/adding a view?
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
If the view you are "removing" is created by a class...
For example..I have a Custom toast message class, that I call and display ove an Activity, making it its parent... After displaying, I remove it, thus allowing the S.O. to clean up resources if/when needed...
 
Upvote 0
Top