update Fragment - Android User Interface

Android examples for User Interface:Fragment

Description

update Fragment

Demo Code


//package com.java2s;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import java.util.List;

public class Main {
    public static void updateFragment(FragmentManager fragmentManager) {
        Fragment currentFragment = getVisibleFragment(fragmentManager);
        if (currentFragment == null) {
            return;
        }/*from  ww w . j a  v a 2 s.com*/

        FragmentTransaction fragTransaction = fragmentManager
                .beginTransaction();
        fragTransaction.detach(currentFragment);
        fragTransaction.attach(currentFragment);
        fragTransaction.commit();
    }

    public static Fragment getVisibleFragment(
            FragmentManager fragmentManager) {
        List<Fragment> fragments = fragmentManager.getFragments();
        for (Fragment fragment : fragments) {
            if (fragment != null && fragment.isVisible())
                return fragment;
        }
        return null;
    }
}

Related Tutorials