Android examples for User Interface:View
The fragment is added to the container view with id frameId .
//package com.java2s; 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 { /**/*w w w .ja va2 s .c om*/ * The {@code fragment} is added to the container view with id {@code frameId}. The operation is * performed by the {@code fragmentManager}. */ public static void addFragmentToActivity( @NonNull FragmentManager fragmentManager, @NonNull Fragment fragment, int frameId, boolean saveToBackStack, String tag) { FragmentTransaction transaction = fragmentManager .beginTransaction(); transaction.add(frameId, fragment, tag); if (saveToBackStack) { transaction.addToBackStack(null); } transaction.commit(); } }