2013-06-23 75 views
0

我在將mapfragments更改爲其他片段時遇到了問題。 (Listfragment或text) 當我使用fragmenttransaction到只有文本的片段。地圖仍然在那裏,新的片段在地圖上。我無法刪除地圖。從mapfragments到其他片段的交易

我搜索了它,但沒有找到好的方法。 有人可以提供一些想法?

這是主要的activity.that延伸活動 進入這裏代碼

protected void onCreate(Bundle savedInstanceState) { 
     if (android.os.Build.VERSION.SDK_INT > 9) { 
      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); 
      StrictMode.setThreadPolicy(policy); 
     } 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
FragmentManager myfm = getFragmentManager(); 
FragmentTransaction ft = myfm.beginTransaction(); 
mymap = new StartFragment(); 
    ft.add(R.id.map, mymap); 
    ft.commit(); 

這是activity_main的片段;

<fragment 
    android:id="@+id/map" 
    android:name="com.google.android.gms.maps.MapFragment" 
    android:layout_below="@+id/Deerfield" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

這是start_fragment類

public class StartFragment extends Fragment { 
@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle  savedInstanceState) { 
     View view = inflater.inflate(R.layout.map_layout,null); 
    return view; 
} 
} 

然後map_layout

<?xml version="1.0" encoding="utf-8"?> 
<fragment xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/map" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
class="com.google.android.gms.maps.MapFragment"/> 

謝謝!

+0

爲什麼你想用另一個包含'MapFragment'的片段替換'MapFragment'? –

回答