2013-05-04 103 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();