Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;

public class Main {
    public static void replaceFragmentToLayout(final int containerId, final FragmentManager fragmentManager,
            final Fragment fragment, final String tag) {
        final FragmentTransaction ft = fragmentManager.beginTransaction();
        final Fragment previousFragment = fragmentManager.findFragmentByTag(tag);
        if (previousFragment != null) {
            ft.remove(previousFragment);
        }
        ft.add(containerId, fragment, tag);
        ft.commit();
    }
}