2013-05-04 102 views
1

我想使用Actionbarsherlock与选项卡栏和其中一个水龙头我想要一张地图。 我已经在谷歌地图v2的sherlockfragment中成功创建了一张地图,但是我希望以编程方式将地图添加到地图中。actionbarsherlock sherlockfragment谷歌地图V2是空的

public class Map_fragment extends SherlockFragment { 
static final LatLng Cph = new LatLng(55.702355,12.436523); 
private final static String MAP_TAG = "map"; 
private GoogleMap mMap; 
SupportMapFragment mMapFragment; 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState){ 
    SupportMapFragment map = (SupportMapFragment) (getSherlockActivity().getSupportFragmentManager().findFragmentByTag(MAP_TAG)); 
    if(map==null){ 
     Log.d("MAP", "NULL"); 
     } 
    if(map!=null){ 
    Log.d("MAP", " " + map); 
    Log.d("GETMAP", " " + map.getMap()); 
    } 


    //GoogleMap mMap = map.getMap(); 
    //mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(Cph, 14)); 
    return inflater.inflate(R.layout.mapv2_layout, container, false); 


} 
@Override 
public void onViewCreated(View view, Bundle savedInstanceState){ 
    super.onViewCreated(view, savedInstanceState); 

} 
@Override 
public void onCreate(Bundle savedInstanceState){ 
    super.onCreate(savedInstanceState); 

} 
@Override 
public void onAttach(Activity activity) { 
    // TODO Auto-generated method stub 

    super.onAttach(activity); 
} 
public void setupMap(){ 
    Log.d("SUCCESS" , "SUCCESS"); 
} 
} 

我试图与其他网站和堆栈溢出的帖子很多不同的意见,但地图总是空。

我已经尝试过使用onCreate和onAttach后,从别人的建议,但没有运气。

我已经尝试了很长的时间和我将要拉我的头发:(

回答

0

我解决它通过手动添加SherlockMapFragment类的ActionBarSherlock库,发现这里http://code.google.com/p/opendatakit/source/browse/src/com/actionbarsherlock/app/SherlockMapFragment.java?spec=svn.tables.35872cc920b5668de433c6fc81efc86c4970bac1&repo=tables&r=0c1b0212e5b8bb5af8ce2b8e9357cd30e3870084

然后用下面的线我终于得到了“gMap”,这是非空

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