push Fragment to FragmentActivity - Android User Interface

Android examples for User Interface:Fragment

Description

push Fragment to FragmentActivity

Demo Code


//package com.java2s;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;

public class Main {
    static public void pushFragment(
            final FragmentActivity fragmentActivity, final Fragment fragment) {
        final View rootView = fragmentActivity.getWindow().getDecorView()
                .findViewById(android.R.id.content);

        final FragmentManager fragmentManager = fragmentActivity
                .getSupportFragmentManager();
        final FragmentTransaction transaction = fragmentManager
                .beginTransaction();//w w  w  . jav  a2 s .c om

        transaction.replace(rootView.getId(), fragment);
        transaction.addToBackStack(fragment.toString());
        transaction.commit();
    }
}

Related Tutorials