Reputation: 5031
Cannot add to fragment transaction due to the following error, how would you go about this?
add() in FragmentTransaction cannot be applied to:
Expected Parameters: Actual Arguments:
int R.id.mapWithOverlay
android.support.v4.app.Fragment _mapFragment (com.google.android.gms.maps.MapFragment)
String "map"
Code is as follows:
android.support.v4.app.FragmentTransaction fragTx = getSupportFragmentManager().beginTransaction();
if (fragTx != null) {
_mapFragment = MapFragment.newInstance(mapOptions);
fragTx.add(R.id.mapWithOverlay, _mapFragment, "map");
fragTx.commit();
} else {
Toast.makeText(this, "Could not display the map", Toast.LENGTH_SHORT).show();
}
Thanks in advance.
Upvotes: 3
Views: 1827
Reputation: 5031
I changed to the following to get it to work, hopefully this will help others?
FragmentTransaction fragTx = getFragmentManager().beginTransaction();
if (fragTx != null) {
_mapFragment = MapFragment.newInstance(mapOptions);
fragTx.add(R.id.mapWithOverlay, _mapFragment, "map");
fragTx.commit();
} else {
Toast.makeText(this, "Could not display the map", Toast.LENGTH_SHORT).show();
}
Upvotes: 0
Reputation: 35661
Are you using SupportMapFragment
(from the Support package) and not MapFragment
The regular MapFragment
not work with SupportFragmentManager
.
See the difference?
private class MyMap1 extends SupportMapFragment {
}
private class MyMap2 extends MapFragment {
}
Upvotes: 7