2013-03-01 1 views
1

J'essaie d'ajouter un google mapview à un fragment existant. En suivant les instructions des développeurs docs, j'ai inclus le code XML suivant dans mon fragment:IllegalArgumentException lors de l'ajout de Google Maps Android v2 au fragment

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

Cependant, je finis par obtenir un IllegalArgumentException chaque fois:

02-28 18:54:21.133: E/AndroidRuntime(11300): Caused by:  java.lang.IllegalArgumentException: Binary XML file line #158: Duplicate id 0x7f050019, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment 

02-28 18: 54: 21.133: E/AndroidRuntime (11300): à android.support.v4.app.FragmentActivity.onCreateView (FragmentActivity.java:285) 02-28 18: 54: 21.133: E/AndroidRuntime (11300): à android. view.LayoutInflater.createViewFromTag (Layout

Des solutions de contournement pour cela?

+0

En fait, vous essayez d'ajouter MapFragment (à partir de votre code) et non une vue de carte. et je ne pense pas que ce soit possible parce que les fragments sont conçus pour s'asseoir à l'intérieur des activités et non d'autres fragments. –

+0

Est-il possible d'ajouter un MapView sans utiliser MapFragment? Idéalement, j'aimerais simplement inclure un MapView dans ma mise en page, comme n'importe quel autre widget. Merci! – munkay

+0

À ce que je sache, MapView est un objet API V1 de GoogleMaps et ne peut pas être utilisé dans V2. qu'essayez-vous exactement d'accomplir? –

Répondre

0

Vous ne pouvez pas gonfler une mise en page dans un fragment quand cette mise en page comprend un fragment http://developer.android.com/about/versions/android-4.2.html#NestedFragments

MapFragment doit être ajouté dynamiquement dans le code, par exemple:

MapFragment fragment = new MapFragment(); 
FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); 
transaction.add(R.id.mapView, fragment).commit(); 

et mise en page xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

<FrameLayout 
    android:id="@+id/mapView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 
</FrameLayout> 

</RelativeLayout> 
Questions connexes