Into my project I am using viewpager with three tabs named History,Main,Map.Main activity contain Timer,stopwatch,etc
Here's my solution (used in each of the fragments) , which allows both smoothness and avoids memory problems:
...
private LayoutInflater mInflater;
private WeakReference mRootView = null;
...
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState)
{
if (inflater != null)
mInflater = inflater;
else
mInflater = LayoutInflater.from(getActivity());
View rootView = mRootView == null ? null : mRootView.get();
if (rootView != null)
{
final ViewParent parent = rootView.getParent();
if (parent != null && parent instanceof ViewGroup)
((ViewGroup) parent).removeView(rootView);
}
else
{
rootView = mInflater.inflate(R.layout.fragment_test, null, false);
mRootView = new WeakReference(rootView);
}
return rootView;
}