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();//from   w  ww. jav  a  2  s  .c  om
        transaction.add(frameId, fragment);
        transaction.commit();
    }

}

Related Tutorials