Loads a fragment in a container - Android User Interface

Android examples for User Interface:Fragment

Description

Loads a fragment in a container

Demo Code

/**//w  w w.j  a  v a  2  s  . c  o  m
 * thesocialcoin
 * <p/>
 * Created by Lluis Ruscalleda Abad on 14/07/15.
 * Copyright (c) 2015 Identitat SL. All rights reserved.
 */
//package com.java2s;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;

public class Main {
    /**
     * Loads a fragment in a container
     *
     * @param fragment    : El fragment que se quiere colocar
     * @param containerID : El id del contenedor donde se va a colocar el fragment
     */
    public static void loadFragment(Fragment fragment, int containerID,
            FragmentActivity activity) {
        FragmentTransaction transaction = activity
                .getSupportFragmentManager().beginTransaction();
        transaction.replace(containerID, fragment);
        transaction.setTransition(FragmentTransaction.TRANSIT_NONE);
        transaction.commit();
    }
}

Related Tutorials