I wish to insert a Android map v2 into a fragment, but my restiction is that I can't use .xml files. The problem appears when I try to instantiate the MapFragment. Here is the code:
public class LocationFragment extends Fragment{
private static View view;
private static GoogleMap mMap;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (container == null) {
return null;
}
view = (RelativeLayout) inflater.inflate(R.layout.location_fragment, container, false);
setUpMapIfNeeded(); // For setting up the MapFragment
MapFragment mf = new MapFragment();
return view;
}
/***** Sets up the map if it is possible to do so *****/
public static void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
FragmentManager manager = MapActivity.fragmentManager;
MapFragment smf = (MapFragment) manager.findFragmentById(R.id.location_map);
mMap = smf.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null)
setUpMap();
}
}
Can somebody help me?