此方法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"));
}
}
答案 0 :(得分:1)
使用
mMap = ((SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
而不是
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
答案 1 :(得分:0)
如果要从Fragment访问片段管理器,甚至从支持库,您应该使用 getFragmentManager()方法。
http://developer.android.com/reference/android/app/Fragment.html#getFragmentManager()
http://developer.android.com/reference/android/support/v4/app/Fragment.html#getFragmentManager()