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<View> 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<View>(rootView);
}
return rootView;
}
I have also faced this problem.
You can solve it by just add single line mViewPager.setOffscreenPageLimit(3);
public class SwipeyTabsSampleActivity extends FragmentActivity {
...
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mViewPager = (ViewPager) findViewById(R.id.viewpager);
mTabs = (SwipeyTabs) findViewById(R.id.swipeytabs);
SwipeyTabsPagerAdapter adapter = new SwipeyTabsPagerAdapter(this,
getSupportFragmentManager());
mViewPager.setAdapter(adapter);
mViewPager.setOffscreenPageLimit(3); <------ Add this one
}
}
Good Luck.