add Fragment - Android User Interface

Android examples for User Interface:Fragment

Description

add Fragment

Demo Code


//package com.java2s;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.ViewGroup;

public class Main {
    public static void addFragment(Fragment fragment,
            FragmentActivity activity, int fragHolderLayout) {
        ViewGroup view = (ViewGroup) activity
                .findViewById(fragHolderLayout);
        view.removeAllViews();//w  ww .j a  va  2  s  .c  o m
        FragmentTransaction fragTransaction = activity
                .getSupportFragmentManager().beginTransaction();
        fragTransaction.replace(fragHolderLayout, fragment);
        fragTransaction.commit();
    }
}

Related Tutorials