HERE Android SDK Developer's Guide

Adding a MapFragment at Runtime

Earlier tutorials in this document featured adding a MapFragment to an activity by editing the layout XML file. You can also add a MapFragment to an activity dynamically, during runtime, by performing the following steps in the Activity class:

  1. Create a layout container:
    final int CONTAINER_ID = 1234567;
    LinearLayout layoutContainer = new LinearLayout(this);
  2. Define a map tag:
    final String MAP_TAG = "map_tag";
  3. Create a map fragment and add it using the fragment manager:
    mapFragment = new MapFragment();
    getFragmentManager().beginTransaction().add(layoutContainer.getId(), mapFragment, MAP_TAG).commit();
  4. Initialize the map fragment by implementing OnEngineInitListener:
    MyOnEngineInitListener onEngineInitListener = new MyOnEngineInitListener();
    ApplicationContext context = new ApplicationContext(this);
    mapFragment.init(context, onEngineInitListener);
  5. Finally, show the content view:

For more information on adding a fragment at runtime, see this article:

You cannot use this account to purchase a commercial plan on Developer Portal, as it is already associated to plans with different payment methods.

To purchase a commercial plan on Developer Portal, please register for or sign in with a different HERE Account.

Something took longer than expected.

The project should be available soon under your projects page.

Sorry, our services are not available in this region.

Something seems to have gone wrong. Please try again later.

We've detected that your account is set to Australian Dollars (AUD).
Unfortunately, we do not offer checkouts in AUD anymore.
You can continue using your current plan as normal, but to subscribe to one of our new plans,
please register for a new HERE account or contact us for billing questions on