HERE SDK for Android (Premium Edition)
SDK for Android Developer's Guide

Adding a AndroidXMapFragment at Runtime

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

  1. Create a layout container:
    final int CONTAINER_ID = View.generateViewId();
    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 AndroidXMapFragment();
    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: