Skip to content

Instantly share code, notes, and snippets.

@MohammedRashad
Last active April 13, 2017 23:55
Show Gist options
  • Save MohammedRashad/c99daf8c53c5dd5e6a4893baa7c06a0e to your computer and use it in GitHub Desktop.
Save MohammedRashad/c99daf8c53c5dd5e6a4893baa7c06a0e to your computer and use it in GitHub Desktop.
Helper Class to move between fragments in android
package com.dummy.app;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
public class FragmentChange {
FragmentTransaction fragmentTransaction;
public void setCurrentFragment(Fragment newFragment, Context mContext) {
fragmentTransaction = mContext.getSupportFragmentManager().beginTransaction();
fragmentTransaction.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right, R.anim.enter_from_right, R.anim.exit_to_left);
fragmentTransaction.replace(R.id.mainFrame, newFragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
@SilatJedi
Copy link

Thanks for this. I had to tweak it, but it gave me that right idea. Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment