I am having an Activity where I am having a ListView, but on click of a Button, I want to replace the ListView with a MapView.
I’ve some options to do this, like having MapView loaded in the Layout already, but setting it’s visibility to View.GONE and make it visible only when the user clicks on the button.
Another option would be to use a removeView() and addView(), however I can’t do this as the Layout is LinearLayout and the View should be added in middle of it.(Don’t know if there’s any method to do it).
Last option is to use ViewStub, however I’ve never used it before.
Which of the above option is best performance-wise and why? Considering the user can switch between ListView and MapView multiple times.
Edit: Forgot to mention ViewSwitcher, never used it before too.
After searching a lot, I’ve come to know these things –
Adding and removing Views would be too bad and prone to crashes.
Setting Visibility is a good option, however, the performance doesn’t improve.
Using
ViewStubis better solution, as the initial loading time is reduced.Using
ViewFlipperis also very easy to use solution. It’s so easy that I ended up usingViewFlipperin my application and there’s no major impact on performance.(Main reason was it’s easy to added animation in it)I am trying to use ViewStub in ViewFlipper. I’ll let you know when I’ll be successful in doing it.
PS: The question is still open to answers. Let me know if I made any mistake here.