show Existing Fragment By Tag - Android User Interface

Android examples for User Interface:Fragment

Description

show Existing Fragment By Tag

Demo Code


//package com.java2s;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.Context;
import android.app.Activity;

public class Main {

    public static boolean showExistingFragmentByTag(Context context,
            String tag) {/*w  w w .j a va  2  s  . c o m*/
        Fragment fragment = ((Activity) context).getFragmentManager()
                .findFragmentByTag(tag);
        if (fragment != null) {
            FragmentTransaction ft = ((Activity) context)
                    .getFragmentManager().beginTransaction();
            ft.show(fragment);
            ft.commit();
            return true;
        }
        return false;
    }
}

Related Tutorials