我正在尝试实现 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;
}
}
我收到一个错误,指出 MapFragment 类型的 getSupportFragmentManager() 未定义。不过,我有点困惑,因为我导入了 com.google.android.gms.maps.SupportMapFragment。那么这个方法不应该来自那里吗?我是否错过了使此方法发挥作用的一些步骤?
如果你正在使用这个Sherlock地图片段 https://stackoverflow.com/a/13727539/1267661, try:
getSherlockActivity().getSupportFragmentManager();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)