Get a Fragment from Activity - Android Activity

Android examples for Activity:Activity Fragment

Description

Get a Fragment from Activity

Demo Code


//package com.java2s;
import android.app.Activity;
import android.app.Fragment;

public class Main {
    /**/*from   ww w. ja v a 2  s.  co m*/
     * Get a Fragment
     * @param activity The Activity using the Fragment
     * @param resId The ID of the Fragment
     * @return The Fragment
     */
    public static Fragment getFragment(Activity activity, int resId) {
        return activity.getFragmentManager().findFragmentById(resId);
    }
}

Related Tutorials