私は次のレイアウトを持っています。これを mapFragment.xml と呼びましょう
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragmentId"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
android:orientation="vertical">
<com.google.android.gms.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapIdfragmentId"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</fragment>
タブビューで使用されます。これは 3 の最初のタブです。タブ ビューをロードするとき、これがロードされる最初のタブです。ここでは問題ありません。2 番目のタブに移動してから戻ると、問題はありません。しかし、3 番目のタブに移動して戻ろうとすると (2 番目または最初のタブに関係なく)、最初のタブの onCreate メソッドに NPE があります。
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View v = inflater.inflate(R.layout.mapFragment, container, false);
return v;
}
NPE は 2 行目で発生します - View v = .... 例外の根本的な原因は
Caused by: java.lang.IllegalArgumentException: Binary XML file line #7: Duplicate id 0x7f040005, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.MapFragment
E/AndroidRuntime(17423): at android.app.Activity.onCreateView(Activity.java:4722)
Sherlock ライブラリを使用しており、デバイスは Android v2.2.2 で実行されています
PS: ここで推奨される解決策 - com.google.android.gms.maps.MapFragment の別のフラグメントを使用して ID を複製する、null をタグ付けする、または親 ID を指定すると問題は解決しますが、その後、マップは完全にフリーズします:(