找不到符号方法" getSupportFragmentManager()"

时间:2015-06-06 09:05:42

标签: android

此方法getSupportFragmentManager()属于FragmentActivity, 如果我只使用extends Fragment

,如何替换此方法

我收到此错误

  

错误:(30,42)错误:找不到符号方法getSupportFragmentManager()

public class MapsFragment extends FragmentActivity中使用此代码:

public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
  final View view = inflater.inflate(R.layout.fragment_maps,container, false);   
  if (mMap == null) {
    // Try to obtain the map from the SupportMapFragment.
    mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
    // Check if we were successful in obtaining the map.
    if (mMap != null) {
      mMap.addMarker(new MarkerOptions().position(new LatLng(57.70, 11.96)).title("Marker"));
      }
    }

2 个答案:

答案 0 :(得分:1)

使用

mMap = ((SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

而不是

mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

答案 1 :(得分:0)