I'm trying to load SupportMapFragment dynamically in a fragment, here is my onCreateView() method:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View contentView = inflater.inflate(R.layout.frag_map_layout, null);
shopDtos=ShopListFragment.shopDtos;
fragment =SupportMapFragment.newInstance();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.map_content, fragment);
ft.commit();
map = fragment.getMap();
mapMarker = map.addMarker(new MarkerOptions().position(new LatLng(0, 0))
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.maps_pin)));
return contentView;
}
Unfortunately, I get the GoogleMap map as null
.
Any suggestions on to how create a mapfragment dynamically?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…