Skip to content Skip to sidebar Skip to footer

Removeallviews() Error When Retaining Fragment Instance

I am trying to retain my fragment instance on orientation change. I use the below code in my fragment. private View fragmentLayoutView; private ListView myListView; @Override publ

Solution 1:

I had to remove all the views of the fragment layout's parent :

((ViewGroup) fragmentLayoutView.getParent()).removeAllViews();

Then check if the adaptor is null before initializing the adaptor and listview :

@OverridepublicvoidonActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    if(myCustomCursorAdaptor == null){
        myListView = (ListView) getActivity().findViewById(R.id.listview1);
        myCustomCursorAdaptor = newMyCustomCursorAdaptor(getActivity());
        myListView.setAdapter(myCustomCursorAdaptor);
    }
    ...
}

Post a Comment for "Removeallviews() Error When Retaining Fragment Instance"