Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8151529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:25:09+00:00 2026-06-06T15:25:09+00:00

I have 4 views that are controlled by 1 SherlockMapActivity. Currently I am switching

  • 0

I have 4 views that are controlled by 1 SherlockMapActivity. Currently I am switching between views with the tabs by removeAllViews() and then re-inflate the view again. This seams like a very inefficient way of going about it.

Is there any way to just “hide” a view that has been inflated already and re-position a new view to the front? I have tried every variation of setVisibility, etc, to no avail. Here is how I am going about it right now:

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    //load our views!
    this.baseViewGroup = (ViewGroup)this.findViewById(android.R.id.content);

    this.mapView = new MapView(ActivityMain.this, MAP_API_KEY);
    this.mapView.setClickable(true);

    this.createMenu();
}

@Override
public void onTabSelected(Tab tab, FragmentTransaction ft)
{
    Log.v(CLASS_NAME, "tab selected: "+tab.getPosition());

    if (0 == tab.getPosition())
    {
        this.baseViewGroup.removeAllViews();
        this.getLayoutInflater().inflate(R.layout.map, this.baseViewGroup);
    }
    else if (1 == tab.getPosition())
    {
        this.baseViewGroup.removeAllViews();
        this.getLayoutInflater().inflate(R.layout.list, this.baseViewGroup);
    }
}

I can then do fancy things with ViewControllers (of sorts) to restart the previous state of the view when it is re-created but this just seams crazy. Is there a better way to do this?

Edit
I have tried saving the views (inflate once, remove but then just re-add) but I get this strange behavior. Basically, all inflated views are shown on top of each other, in a semi-transparent way. No amount of setVisibility() makes them totally go away.

The code I tried (added to onCreate() and onTabSelected() where appropriate):

//in onCreate()
this.mapLayout = this.getLayoutInflater().inflate(R.layout.map, this.baseViewGroup);
this.moreLayout = this.getLayoutInflater().inflate(R.layout.more, this.baseViewGroup);

//in onTabSelected()
ViewGroup content = (ViewGroup)this.mapLayout.getParent();
content.removeAllViews();
content.addView(this.mapLayout);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T15:25:11+00:00Added an answer on June 6, 2026 at 3:25 pm

    Donot inflate views again and again. instead, have 4 class level view variables like

    private View firstView;
    private View secondView;
    private View thirdView;
    private View fourthView;
    

    now during every tab change/press. remove all child views from parent and add, appropriate view to the parent. like,

    parentView.removeAllViews();
    parentView.addView(secondView);
    

    Edit:

    Pass null for parentView.

    instead of this,

    this.moreLayout = this.getLayoutInflater().inflate(R.layout.more, this.baseViewGroup);
    

    do this,

    this.moreLayout = this.getLayoutInflater().inflate(R.layout.more, null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this is extremely silly. I have a view controller that scans a
I have two views controlled by a uinavigationcontroller. the first view has a UIWebView
I have 2 views controlled by a tab bar controller. The issue that I
I have three views that I switch between using a tab bar, and the
I have a form that has two views. These views are controlled by radio
If I have a stack of views controlled by a view controller, and a
I have an XCode project I am working on that has multiple views controlled
My controller is decorated with [HandleError] and [HandleError(ExceptionType=typeof(CustomException), View=CustomView)] . I have views that
In my application I want to have one view that holds 2 partial views.
I have a view controller based app that contains several views that I display/hide

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.