While adding user interface to a fragment it is shown to inflate the view each an every call to onCreateView:
public static class ExampleFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.example_fragment, container, false);
}
}
reference: http://developer.android.com/guide/components/fragments.html#UI
What if I cache the view inflated and return it on next calls such as:
public static class ExampleFragment extends Fragment {
private View mView = null;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if(mView == null){
mView = inflater.inflate(R.layout.example_fragment, container, false);
}else{
//detach mView from previous parent if exist
...
}
return mView;
}
}