Skip to content

Instantly share code, notes, and snippets.

@code-twister
Last active September 6, 2017 09:51
Show Gist options
  • Save code-twister/731d60aca8af6fe212fe151500c8f58e to your computer and use it in GitHub Desktop.
Save code-twister/731d60aca8af6fe212fe151500c8f58e to your computer and use it in GitHub Desktop.
@Override
public Object instantiateItem(View container, int position) {
if (mCurTransaction == null) {
mCurTransaction = mFragmentManager.beginTransaction();
}
// Do we already have this fragment?
String name = makeFragmentName(container.getId(), position);
Fragment fragment = mFragmentManager.findFragmentByTag(name);
if (fragment != null) {
if (DEBUG) Log.v(TAG, "Attaching item #" + position + ": f=" + fragment);
mCurTransaction.attach(fragment);
} else {
fragment = getItem(position);
if (DEBUG) Log.v(TAG, "Adding item #" + position + ": f=" + fragment);
mCurTransaction.add(container.getId(), fragment,
makeFragmentName(container.getId(), position));
}
if (fragment != mCurrentPrimaryItem) {
fragment.setMenuVisibility(false);
}
return fragment;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment