add Fragment To Activity - Android Activity

Android examples for Activity:Activity Fragment

Description

add Fragment To Activity

Demo Code

import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

public class Main{
    public static void addFragmentToActivity(
            @NonNull FragmentManager fragmentManager,
            @NonNull Fragment fragment, int frameId) {

        FragmentTransaction transaction = fragmentManager
                .beginTransaction();//  ww  w  . j  a v  a 2  s  .  c  o  m
        transaction.add(frameId, fragment);
        transaction.commit();
    }
}

Related Tutorials