Java tutorial
//package com.java2s; 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(FragmentManager fragmentManager, Fragment fragment, int frameId) { if (fragmentManager == null || fragment == null) { throw new NullPointerException(); } FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.add(frameId, fragment); transaction.commit(); } }