I have got the following problem. I am trying to preserve my layout of one of my fragments on configuration change. Therefore I thought, I would be able to use setRetainInstance(true)
. However, it turned out not to work. The problem is, that onCreateView
gets called each time on configuration change so that my layout gets reset to the initial state.
What can I do to preserve my layout?
Will I have to move my code inside onCreateView
somewhere else?
Please note: I cannot use the hack in the manifest with android:configChanges="orientation"
since my tab hosting activity hosts more tabs. I only want to retain the state in one tab.
Here is some of my code:
public class MyFragment extends SherlockFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
setRetainInstance(true);
View rootView = inflater.inflate(R.layout.abc, container, false);
// Some more code that was omitted ..
return rootView;
}
}