Last active
December 29, 2015 01:59
-
-
Save kingori/7597001 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void pushFragments(String tag, Fragment fragment, | |
boolean shouldAnimate, boolean shouldAdd) { | |
if (shouldAdd) | |
mStacks.get(tag).push(fragment); | |
FragmentManager manager = getSupportFragmentManager(); | |
FragmentTransaction ft = manager.beginTransaction(); | |
ft.replace(R.id.realtabcontent, fragment).addToBackStack(null); | |
ft.commit(); | |
} | |
public void popFragments() { | |
if( mStacks.get(mCurrentTab).size() - 2 < 0) { | |
super.finish(); | |
return; | |
} | |
Fragment fragment = mStacks.get(mCurrentTab).elementAt( | |
mStacks.get(mCurrentTab).size() - 2); | |
mStacks.get(mCurrentTab).pop(); | |
FragmentManager manager = getSupportFragmentManager(); | |
FragmentTransaction ft = manager.beginTransaction(); | |
ft.replace(R.id.realtabcontent, fragment); | |
ft.commit(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
Bundle savedInstanceState) { | |
return inflater.inflate(R.layout.fragment_tab, container, false); | |
} | |
ViewPager mViewPager; | |
@Override | |
public void onViewCreated(View view, Bundle savedInstanceState) { | |
super.onViewCreated(view, savedInstanceState); | |
mViewPager= (ViewPager) view.findViewById(R.id.viewPager); | |
} | |
public void onActivityCreated(Bundle savedInstanceState) { | |
super.onActivityCreated(savedInstanceState); | |
} | |
public void onResume() { | |
super.onResume(); | |
mViewPager.setAdapter(new MyAdapter(getChildFragmentManager())); | |
} | |
public static class MyAdapter extends FragmentStatePagerAdapter { | |
public MyAdapter(FragmentManager fm) { | |
super(fm); | |
} | |
@Override | |
public int getCount() { | |
return 4; | |
} | |
@Override | |
public Fragment getItem(int position) { | |
return detailPageFragment.newInstance(String.valueOf(position)); | |
} | |
@Override | |
public CharSequence getPageTitle(int position) { | |
return "Fragment # " + position; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment