0

This is from a simple app with a listView and a google maps fragment. the listview is populated with preset locations. following code works for the first time the user touches a list item (i.e. opens the location specified within the "Locale" object) this is from my main activity:

@Override
public void onLocale(Locale locale) {

    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    // find the map fragment
    Fragment mapFrag = DetailFrag.newInstance(locale);
    if (isSingleLayout() == true) {
        ft.replace(R.id.fragment_container, mapFrag, "map");
        ft.addToBackStack(null);
    } else {
        ft.replace(R.id.fragment_container_details, mapFrag,
                "map");
    }

    ft.commit();

}

and this is the fragment's onCreateView method, which crashes:

 public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    try {
        View v = inflater.inflate(R.layout.frag_details, container, false);
        Bundle details = getArguments();
        float x = details.getFloat("x");
        float y = details.getFloat("y");
        FragmentManager fm = getFragmentManager();
        SupportMapFragment innerMapFrag = (SupportMapFragment) fm
                .findFragmentById(R.id.map);
        // get the map object out of the map
        GoogleMap map = innerMapFrag.getMap();
        // set the map style
        map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
        // set the map camera position:
        LatLng location = new LatLng(x, y);
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(location, 15));

        return v;
    } catch (InflateException e) {

        Log.e(LOG,e.toString());
        return null;
    }
}
Kepedizer
  • 826
  • 2
  • 10
  • 24
  • 1
    What's the exception ? – Greg Giacovelli Dec 02 '13 at 01:47
  • inflateException Binary XML file line #7: Error inflating class fragment – Kepedizer Dec 02 '13 at 01:50
  • http://stackoverflow.com/a/17405949/2684237 This (after changing getSherlock... to getActivity) solved the problem partially - it doesn't throw the exception anymore. Now when I click on the second item it deletes the old map, but I have to click again to get a new map – Kepedizer Dec 02 '13 at 01:52

1 Answers1

0

try this, it might help you ^^

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (view != null) {
        ViewGroup parent = (ViewGroup) view.getParent();
        if (parent != null) {
            parent.removeView(view);
        }
    }
    try {
        view = inflater.inflate(R.layout.restaurants_map, container, false);
    } catch (InflateException e) {
        LOGGER.error("map view already exist.");
    }
    return view;
}
worawee.s
  • 598
  • 5
  • 11