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 7445043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:43:31+00:00 2026-05-29T11:43:31+00:00

My app is using a ListFragment on left side that the user can use

  • 0

My app is using a ListFragment on left side that the user can use to select what fragment to use on the right hand side.

In sort it seems impossible to show the MapView more than once. The first problem is that it only allow one instance of MapView per Activity.

# Exception 1:
You are only allowed to have a single MapView in a MapActivity

Therefore, I saved my MapView and container in the Activity class:

public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   FragmentManager.enableDebugLogging(true);
   setContentView(R.layout.main);
   mapViewContainer = LayoutInflater.from(this).inflate(R.layout.maplayout, null);
   mapView = (MapView) mapViewContainer.findViewById(R.id.map_view); 
}

However, this give me the next problem:

# Exception 2:
The specified child already has a parent. 
You must call removeView() on the child’s parent first.

I have tried to remove the view, using this code:

((ViewGroup)mapViewContainer).removeView(mapView);
((ViewGroup)mapView.getParent()).removeView(mapView);

Got a NullPointerExeption.

I would appreciate any good ideas, or if you could share if you have been successful in doing this?

Thanks 🙂

  • 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-05-29T11:43:32+00:00Added an answer on May 29, 2026 at 11:43 am

    Yeah, bumped into this one, too.

    Do not add your MapView in XML layout file for your fragment. Instead, just leave a place for it, say, in a LinearLayout with id=”@+id/your_map_container_id”

    Declare a MapView private member in YourMapContainerFragment’s:

    public class YourMapContainerFragment extends Fragment {
        private MapView mMapView;
        //...
    

    Then, go like this in YourMapContainerFragment’s onCreateView():

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // ... Inflate your fragment's layout...
        // ...
        if (mMapView == null) {
            mMapView = new MapView(getActivity(), /*String*/YOUR_MAPS_API_KEY);
        } else {
            ((ViewGroup)mMapView.getParent()).removeView(mMapView);
        }
        ViewGroup mapContainer = (ViewGroup) fragmentLayout.findViewById(R.id.your_map_container_id);
        mapContainer.addView(mMapView);
        // ...
    }
    

    This will make the same MapView object be reused across removals/additions of your fragment to activity.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building app using GAE and wanted to use Django for that. Which patch
I have a fragment view that needs replacement with another fragment. When the ListFragment
I'm building an app using Brunch and Backbone.js that is to include nested menus.
I have an app using using Django Nonrel on AppEngine. I'd like to use
i'm using actionbar sherlock/fragments with my app my problem is that i need to
I have an app using a UITabBarController, and I have another view that needs
We are building an app using the MVVM pattern, we have controllers that wire
Building an app using a calendar on a Google Apps domain that has SSL
I want my app using the MFMailComposeViewController to send an email such that the
I have an app (using retain/release, not GC) that maintains an NSArray instance variable,

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.