Nothing Special   »   [go: up one dir, main page]

Skip to content

Instantly share code, notes, and snippets.

@thoretton-edwin
Forked from mpaloulack/gist:10472674
Last active August 29, 2015 13:59
Show Gist options
  • Save thoretton-edwin/10477582 to your computer and use it in GitHub Desktop.
Save thoretton-edwin/10477582 to your computer and use it in GitHub Desktop.
Android remplacer un fragment
Fragment frag;
//ajout d'un fragment
TonFragment newFragment = new TonFragment();
android.support.v4.app.FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.add(R.id.fragment_container, newFragment).addToBackStack("A_B_TAG");
transaction.commit();
//remplacement d'un fragment
frag = new AutreFragment();
android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
android.support.v4.app.FragmentTransaction fragmentTransaction = fm.beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, frag);
fragmentTransaction.setTransition(fragmentTransaction.TRANSIT_FRAGMENT_OPEN);
fragmentTransaction.commit();
// Utuiliser le back button
@Override
public void onBackPressed() {
if (getSupportFragmentManager().findFragmentByTag("FragmentC") != null) {
getSupportFragmentManager().popBackStack("A_B_TAG",
fm.POP_BACK_STACK_INCLUSIVE);
} else {
super.onBackPressed();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment