-
-
Save korniltsev/4690507 to your computer and use it in GitHub Desktop.
fragment reuse
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 void onDestroyView() { | |
super.onDestroyView(); | |
getFragmentManager() | |
.beginTransaction() | |
.detach(mFilter) | |
.commit(); | |
} | |
@Override | |
public void onViewCreated(View view, Bundle savedInstanceState) { | |
findOrCreateFilter(); | |
} | |
private void findOrCreateFilter() { | |
final String tag = "statistic_filter"; | |
FragmentManager fm = getFragmentManager(); | |
mFilter = fm.findFragmentByTag(tag); | |
FragmentTransaction t = fm.beginTransaction(); | |
if (mFilter != null) { | |
t.attach(mFilter); | |
} else { | |
mFilter = Fragment.instantiate(getActivity(), PaymentSystemFilterFragment.class.getName()); | |
t.add(R.id.statistic_filter_container, mFilter, tag); | |
} | |
t.commit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment