Q:

Add Google Map as child of a LinearLayout

I'm building an Android app that composes one of its screen using a selection of elements, each element being a child of a ScreenElement class that again extends LinearLayout. 
My activity queries a database, determines the number of elements and their nature and adds each element to the Layout of the activity. The elements are regular Java classes, but as they, through their parent, extend LinearLayout, I can just add them doing
LinearLayout layout = (LinearLayout) findViewById(R.id.screenLayout);
for(ScreenElement e : screenElements) {
    layout.addView(e);
}

An element can contain all kinds of things, such as Images or text. Now, I want to have an element that can display a Map. The problem is: Google recommends to display a Map in a Fragment, which is not possible (because the holding class is a View, not an Activity or Fragment. There is also MapView that I could use, but all the examples I found (e.g. this or this) use MapView within an Activity, because MapView is required to connect to the overriden functions (onPause, onDestroy,...) of Activity. 
So what I'm basically hoping to find is something that does this (not working code):
public class MapElement extends ScreenElement {
    private MapView mapView;
    private GoogleMap gMap;

    public MapElement(Context con) {
        super(con);

        mapView = new MapView(con);
        gmap = new GoogleMap();

        // Set map options and features, size etc.

        mapView.setMap(gMap);
        this.addView(mapView);
    }
}

Well, except that this does not work. I'd be thankful for every hint you could give me!

A:

You're close with your not working code. You should be able to access the fragmentManager functions if you cast the context you passed in to type Activity.
((MainActivity)con).getSupportFragmentManager()....

and then you can follow the tutorial previously linked

