2013-03-12 71 views
0

這是一個類似的問題:MapFragment in Action Bar Tabs但我沒有明確的答案,我明白了。我是Android新手,這是我開發的第一個應用程序。爲創建MapFragment的活動實施操作欄選項卡

我目前有一個MainActivity可爲Google Maps v2創建一個MapFragment。並顯示動作條下圖所示in this screenshot

我的目標是實現標籤(不使用FragmentActivity S或支持庫爲我的應用程序是minSdkVersion=11)在Eclipse中在MainActivity目前創造了谷歌地圖V2一個MapFragment

MainActivity.java片斷

public class MainActivityextends Activity 
implements LocationListener, LocationSource, OnMarkerClickListener, OnInfoWindowClickListener { 
    private static GoogleMap googleMap; 

    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.map); 
     actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); //Change to Tab mode 
     .... 
     googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap(); 


map.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <include 
    android:id="@+id/map" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    layout="@layout/map_fragment" /> 
</LinearLayout> 


map_fragment.xml

<fragment xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:map="http://schemas.android.com/apk/res-auto" 
android:id="@+id/map" 
android:name="com.google.android.gms.maps.MapFragment" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
map:cameraTargetLat="53.78513542767" 
map:cameraTargetLng="-3.14948167651" 
map:cameraZoom="14" /> 


Eclipse的設置選項卡爲您使用支持庫的活動,因此使用時MapFragment給我(下圖)的錯誤,我恢復到未使用的標籤。這樣做的原因,我認爲是here

Caused by: java.lang.ClassCastException: com.google.android.gms.maps.MapFragment cannot be cast to android.support.v4.app.Fragment 

我需要使用標籤作爲目前唯一一個頁面/活動已經發展,我需要一個方式來顯示過濾器用戶以及地圖。用戶將切換到相鄰的選項卡來編輯過濾器,並能夠切換回地圖選項卡,然後過濾器將被拾取並更改地圖上的標記。

所以簡短的問題是否有一個簡單的方法來實現我的MainActivity.java選項卡?如果這個心不是清楚只是問我細節,但是這對我來說

回答

0

嘗試使用,而不是MapFragment SupportMapFragment非常先進:

map.xml

<fragment xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:map="http://schemas.android.com/apk/res-auto" 
android:id="@+id/map" 
android:name="com.google.android.gms.maps.SupportMapFragment" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
map:cameraTargetLat="53.78513542767" 
map:cameraTargetLng="-3.14948167651" 
map:cameraZoom="14" /> 
相關問題