Skip to content

Instantly share code, notes, and snippets.

@korniltsev
Created February 1, 2013 10:20
Show Gist options
  • Save korniltsev/4690507 to your computer and use it in GitHub Desktop.
Save korniltsev/4690507 to your computer and use it in GitHub Desktop.
fragment reuse
@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