Skip to content Skip to sidebar Skip to footer

Replace, Remove Fragment And Removing View Doesn´t Work In Second Run

My app selects one object of the listview and show the map. Works on first time running but in the second didn´t work. On third it works! This is because of the inflate exception

Solution 1:

Check your onCreateView method. I dont think its the correct way to inflate a xml file in oncreateview method. Please try this:

@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    Viewview= inflater.inflate(R.layout.fragment_layout.,container,false);
    //start inflating the view and return the view
     map = (SupportMapFragment) getFragmentManager().findFragmentById(R.id.map);
    }

A good place to utilize and use view methods is onStart of the fragment.

@OverridepublicvoidonStart() {
    // TODO Auto-generated method stubsuper.onStart();
    mMapView = map.getMap();
  }

Also I see that you are mixing the support package from the fragment. See this line:

android.support.v4.app.FragmentManagerfm= getFragmentManager();

Make sure that all your import's and code for fragment are either from support package or from default package(api 11 or greater). This is a common source of bugs like classcastexception.

Post a Comment for "Replace, Remove Fragment And Removing View Doesn´t Work In Second Run"