add Fragment To Activity - Android android.app

Android examples for android.app:Activity

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();//  www.  j a v  a 2s . c  o m
        transaction.add(frameId, fragment);
        transaction.commit();
    }

}

Related Tutorials