本文介绍了getSupportFragmentManager()方法是未定义的类型MapFragment的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想实现谷歌地图显示和下面是我的codeS:
I'm trying to implement Google Map display and below are my codes:
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有点困惑。不宜此法从那里来的呢?我丢失了一些步骤,在获得这种方法的工作?
Im getting an error that getSupportFragmentManager() is undefined for type MapFragment. However I'm a little confused as I have imported com.google.android.gms.maps.SupportMapFragment. shouldn't this method come from there then? Am I missing out some steps in getting this method to work?
推荐答案
如果你正使用该 SherlockMapFragment ,试试:
If you are using this SherlockMapFragment, try:
getSherlockActivity().getSupportFragmentManager();
这篇关于getSupportFragmentManager()方法是未定义的类型MapFragment的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!