Example usage for android.app FragmentManager beginTransaction

List of usage examples for android.app FragmentManager beginTransaction

Introduction

In this page you can find the example usage for android.app FragmentManager beginTransaction.

Prototype

public abstract FragmentTransaction beginTransaction();

Source Link

Document

Start a series of edit operations on the Fragments associated with this FragmentManager.

Usage

From source file:Main.java

public static void showDialogFragment(final DialogFragment dialog, final String tag,
        final FragmentManager fragmentManager) {
    final FragmentTransaction ft = fragmentManager.beginTransaction();
    final Fragment prev = fragmentManager.findFragmentByTag(tag);
    if (prev != null) {
        ft.remove(prev);/*from w  w w.j  a  va  2s . c o m*/
    }
    ft.add(dialog, tag);
    ft.commitAllowingStateLoss();
}

From source file:Main.java

public static void replaceFragment(FragmentManager manager, int parent, Fragment fragment) {
    FragmentTransaction ft = manager.beginTransaction();
    ft.replace(parent, fragment);/*  ww w.  ja v a 2s .  c o m*/
    ft.addToBackStack(null);
    ft.commit();
}

From source file:Main.java

public static void addFragmentToActivity(FragmentManager fragmentManager, Fragment fragment, int frameId) {
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.add(frameId, fragment);/*w ww  .j  av a  2s .  c  o  m*/
    transaction.commit();
}

From source file:Main.java

public static void addFragmentToLayout(final int containerId, final FragmentManager fragmentManager,
        final Fragment fragment, final String tag) {
    final FragmentTransaction ft = fragmentManager.beginTransaction();
    ft.add(containerId, fragment, tag);/*  ww w . ja  va 2  s .c  o  m*/
    ft.commit();
}

From source file:Main.java

public static void replaceFragmentToLayout(final int containerId, final FragmentManager fragmentManager,
        final Fragment fragment, final String tag) {
    final FragmentTransaction ft = fragmentManager.beginTransaction();
    final Fragment previousFragment = fragmentManager.findFragmentByTag(tag);
    if (previousFragment != null) {
        ft.remove(previousFragment);//from  ww  w.  j  a v  a 2  s .  com
    }
    ft.add(containerId, fragment, tag);
    ft.commit();
}

From source file:com.appdynamics.demo.gasp.twitter.TwitterAuthentication.java

/**
 * Request a Twitter API v1.1 OAuth Token
 * Uses TwitterAuthenticationFragment/*from  w w w .j  a  va 2 s . c  o  m*/
 */
public static void requestTwitterOAuthToken(FragmentActivity activity) {

    FragmentManager fm = activity.getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    TwitterAuthenticationFragment responder = (TwitterAuthenticationFragment) fm
            .findFragmentByTag("TwitterAuthentication");
    if (responder == null) {
        responder = new TwitterAuthenticationFragment();

        ft.add(responder, "TwitterAuthentication");
    }
    ft.commit();
}

From source file:Main.java

public static void removeDialogFragment(final String tag, final FragmentManager fragmentManager) {
    if (fragmentManager == null) {
        return;//from w w  w. j  a  v  a  2s . c  om
    }
    final FragmentTransaction ft = fragmentManager.beginTransaction();
    final Fragment prev = fragmentManager.findFragmentByTag(tag);
    if (prev != null && prev.isAdded()) {
        ft.remove(prev);
    }
    ft.commitAllowingStateLoss();
}

From source file:Main.java

/**
 * The {@code fragment} is added to the container view with id {@code frameId}. The operation is
 * performed by the {@code fragmentManager}.
 *
 *///from  w w  w .  j  a v  a  2s  . com
public static void addFragmentToActivity(@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment,
        int frameId) {
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.add(frameId, fragment);
    transaction.commit();
}

From source file:com.appdynamics.demo.gasp.utils.LocationServices.java

/**
 * Enable location checking (via LocationFragment)
 * @param context the application context
 *//* w w  w.j av  a2 s . com*/
public static void enableLocationChecking(FragmentActivity context) {
    try {
        if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS) {

            // Check current location
            Location location = LocationFragment.getLocation(context);
            if (location != null) {
                Log.d(TAG,
                        "Location: " + String.format("%.6f", location.getLatitude()) + ", "
                                + String.format("%.6f", location.getLongitude()) + " (via "
                                + location.getProvider() + ")" + '\n');
            }

            // Add LocationFragment to enable location updates
            FragmentManager fm = context.getFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();
            LocationFragment locationFragment = new LocationFragment();
            ft.add(locationFragment, "LocationFragment");
            ft.commit();
        } else
            Log.e(TAG, "Google Play Services not available");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void removeFragment(Activity activity, Fragment fragment) {
    if (activity != null) {
        try {/*from  w  w  w  .j  av  a2  s .com*/
            FragmentManager fragmentManager = activity.getFragmentManager();
            fragmentManager.executePendingTransactions();
            if (fragment.isAdded()) {
                FragmentTransaction ft = fragmentManager.beginTransaction();
                ft.remove(fragment);
                ft.commitAllowingStateLoss();
                fragmentManager.executePendingTransactions();
            }
        } catch (Exception e) {
        }
    }
}