android-getSupportFragmentManager()方法未定义类型MapFragment
作者:互联网
我正在尝试实施Google地图显示,下面是我的代码:
package com.fragments;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
public class MapFragment extends SherlockMapFragment {
private GoogleMap mMap;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = super.onCreateView(inflater, container, savedInstanceState);
SupportMapFragment mapFrag= (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.fragment_map);
mMap = mapFrag.getMap();
return root;
}
}
我得到一个错误,getSupportFragmentManager()未定义类型MapFragment.但是我有点困惑,因为我导入了com.google.android.gms.maps.SupportMapFragment.那个方法不应该来自那里吗?我错过了让这种方法起作用的一些步骤吗?
解决方法:
如果您使用的是此SherlockMapFragment,请尝试:
getSherlockActivity().getSupportFragmentManager();
标签:android-maps-v2,android,supportmapfragment 来源: https://codeday.me/bug/20190825/1724105.html