2013-10-15 68 views
0

我正在開發它採用片段標籤的應用程序,我的片段的人使用谷歌地圖V2 「SupportMapFragmentAndroid的碎片谷歌地圖V2:錯誤充氣類

public class A extends Fragment { 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState) 
    { 
    View view = null; 
    view = inflater.inflate(R.layout.all_coffee_shops_view, container, false); 
    map = ((SupportMapFragment) getActivity().getSupportFragmentManager() 
       .findFragmentById(R.id.map)).getMap(); 
    } 
} 

我的xml:

<RelativeLayout 
    android:id="@+id/map_container" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <fragment 
    android:id="@+id/map" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    class="com.google.android.gms.maps.SupportMapFragment" 
    /> 
</RelativeLayout> 

我從這個A片段(A-> B)調用B片段,並且當我從B->返回時,片段onCreateView拋出異常,「android.view.InflateException:二進制XML文件行#132:錯誤充氣類片段「

+0

檢查我的答案上所以在這個環節:http://stackoverflow.com/questions/19353255/how-to-put-google-maps-v2-on-a-fragment-using- viewpager/19354359#19354359 – Arshu

回答

2
public void onDestroyView() { 
    super.onDestroyView(); 
    Log.d(TAG, "onDestroyView"); 

    Fragment f = getActivity() 
      .getSupportFragmentManager().findFragmentById(R.id.map); 
    if (f != null) { 
     getActivity().getSupportFragmentManager() 
     .beginTransaction().remove(f).commit(); 
    } 
} 
6

當一次地圖fragment被創建,並在回來這個片段再次片段onCreateView()被稱爲這就是爲什麼你越來越強制關閉

中包含您的片段地圖

@Override 
public void onDestroyView() { 
    super.onDestroyView(); 

    Fragment f = getFragmentManager().findFragmentById(R.id.map); 
    if (f != null) 
     getFragmentManager().beginTransaction().remove(f).commit(); 
} 

一次嘗試此請評論我有關結果

+0

嘿納爾希REDDY,感謝您回答我的問題...因爲我使用片段選項卡我使用基本容器處理標籤中的視圖層次結構,你的代碼沒有工作,但我用getSupportFragmentManager getFragmentManager,然後它像一個魅力... –