0

この .xml を膨張させると、android.inflate.Exception が発生します。

    <?xml version="1.0" encoding="utf-8"?>
    <com.google.android.maps.MapView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/map"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clickable="true"
        android:apiKey="***"
    />

このクラスは、.xml (fragment_b.xml) をインフレートします。

public class BFragment extends Fragment {

private MapView mMapView;
private GoogleMap googleMap;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
        Bundle savedInstanceState) {
    // inflat and return the layout
    View v = inflater.inflate(R.layout.fragment_b, container, false);
    mMapView = (MapView) v.findViewById(R.id.map);
    mMapView.onCreate(savedInstanceState);
    mMapView.onResume();//needed to get the map to display immediately

    try {
        MapsInitializer.initialize(this.getActivity());
    } catch (GooglePlayServicesNotAvailableException e) {
        e.printStackTrace();
    }

    googleMap = mMapView.getMap();

    return v;
}

}

結果なしで.xmlで多くのことを試しました。

4

1 に答える 1

0

Aren't you mixing map api V1 and map api V2 implementations?

This is map v1:

<com.google.android.maps.MapView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:apiKey="***"
/>

This is how map api V2 would look like:

<com.google.android.gms.maps.MapView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

Since in your XML you have created an instance of map_v1, you are not allowed to invoke onCreate() and onResume() - you have to do that for map_v2 though.

Also you should remember that in map_v2 you must call onCreate(), onResume() only when appropriate event happens in your activity/fragment lifecycle... So you must call those only from your activity/fragment onCreate and onResume

于 2013-07-08T22:53:33.107 に答える