Android FragmentManager - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android FragmentManager class.

This code example shows how to use the following methods:getBackStackEntryCount, popBackStack
        return super.onOptionsItemSelected(item);
    } 
 
    private boolean popFragment() { 
        FragmentManager fm = getFragmentManager();
        if (fm.getBackStackEntryCount() > 0) {
            fm.popBackStack();
            return true; 
        } 
        return false; 
    } 
} 
9
CodeRank
This code example shows how to use the following methods:beginTransaction, findFragmentByTag
public class Utils { 
 
    public static void showAbout(Activity activity) {
 
        FragmentManager fm = activity.getFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        Fragment prev = fm.findFragmentByTag("dialog_about");
        if (prev != null) {
            ft.remove(prev);
        } 
        ft.addToBackStack(null);
 
        new AboutDialog().show(ft,"dialog_about");
    } 
 
    /** 
     * About Dialog 
     */ 
    public static class AboutDialog extends DialogFragment {
 
7
CodeRank
This code example shows how to use the following methods:beginTransaction, findFragmentByTag
    } 
 
    @Override 
    public Object instantiateItem(ViewGroup container, int position) {
        if (mCurTransaction == null) {
            mCurTransaction = mFragmentManager.beginTransaction();
        } 
 
        final long itemId = getItemId(position);
 
        // Do we already have this fragment? 
//        String name = makeFragmentName(container.getId(), itemId); 
        String name = getTag(position);
        Fragment fragment = mFragmentManager.findFragmentByTag(name);
        if (fragment != null) {
            if (DEBUG) Log.v(TAG, "Attaching item #" + itemId + ": f=" + fragment);
            mCurTransaction.attach(fragment);
        } else { 
            fragment = getItem(position);
            if (DEBUG) Log.v(TAG, "Adding item #" + itemId + ": f=" + fragment);
7
CodeRank
This code example shows how to use the following methods:beginTransaction, findFragmentByTag
//	} 
 
	@Override 
	public Object instantiateItem(ViewGroup container, int position) {
		if (mCurTransaction == null) {
			mCurTransaction = mFragmentManager.beginTransaction();
		} 
 
		final long itemId = getItemId(position);
 
		// Do we already have this fragment? 
		String name = makeFragmentName(container.getId(), itemId);
		Fragment fragment = mFragmentManager.findFragmentByTag(name);
		if (fragment != null) {
			Log.d(TAG, "Attaching item #" + itemId + ": f=" + fragment);
			mCurTransaction.attach(fragment);
		} else { 
			fragment = getItem(position);
			Log.d(TAG, "Adding item #" + itemId + ": f=" + fragment);
			mCurTransaction.add(container.getId(), fragment,
6
CodeRank
This code example shows how to use the following methods:findFragmentByTag
	} 
 
	@Override 
	protected void onCancelled() { 
		final FragmentManager fm = activity.getFragmentManager();
		final DialogFragment fragment = (DialogFragment) fm.findFragmentByTag(PROGRESS_FRAGMENT_TAG);
		if (fragment != null && fragment.isVisible()) {
			fragment.dismiss();
		} 
		super.onCancelled(); 
	} 
 
	@Override 
	protected void onPostExecute(final File result) {
		final FragmentManager fm = activity.getFragmentManager();
		final DialogFragment fragment = (DialogFragment) fm.findFragmentByTag(PROGRESS_FRAGMENT_TAG);
		if (fragment != null) {
			fragment.dismiss();
		} 
		super.onPostExecute(result);
6
CodeRank
This code example shows how to use the following methods:beginTransaction, findFragmentByTag
    } 
 
    public static void showDialog(@Nonnull DialogFragment dialogFragment,
                                  @Nonnull String fragmentTag,
                                  @Nonnull FragmentManager fm) {
        final FragmentTransaction ft = fm.beginTransaction();
 
        Fragment prev = fm.findFragmentByTag(fragmentTag);
        if (prev != null) {
            ft.remove(prev);
        } 
        ft.addToBackStack(null);
 
        // Create and show the dialog. 
        dialogFragment.show(ft, fragmentTag);
    } 
 
    public static void showDialog(@Nonnull android.support.v4.app.DialogFragment dialogFragment,
                                  @Nonnull String fragmentTag,
                                  @Nonnull android.support.v4.app.FragmentManager fm) {
6
CodeRank
This code example shows how to use the following methods:beginTransaction, findFragmentByTag
This code example shows how to use the following methods:beginTransaction, findFragmentByTag
        f.show(fm, TAG);
        return f;
    } 
 
    public static void dismissDialog(FragmentManager fm) {
        Fragment f = fm.findFragmentByTag(TAG);
        if (f != null) {
            fm.beginTransaction().remove(f).commit();
        } 
    } 
 
    @Override 
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        ProgressDialog d = new ProgressDialog(getActivity());
        d.setMessage(getArguments().getString(ARG_MESSAGE));
        return d;
    } 
} 
5
CodeRank
This code example shows how to use the following methods:executePendingTransactions
    @Override 
    public void finishUpdate(ViewGroup container) {
        if (mCurTransaction != null) {
            mCurTransaction.commitAllowingStateLoss();
            mCurTransaction = null;
            mFragmentManager.executePendingTransactions();
        } 
    } 
 
    @Override 
    public boolean isViewFromObject(View view, Object object) {
        return ((Fragment)object).getView() == view;
    } 
 
    @Override 
    public Parcelable saveState() {
        Bundle state = null;
        if (mSavedState.size() > 0) {
            state = new Bundle();
            Fragment.SavedState[] fss = new Fragment.SavedState[mSavedState.size()];
6
CodeRank
This code example shows how to use the following methods:executePendingTransactions
    @Override 
    public void finishUpdate(View container) {
        if (mCurTransaction != null) {
            mCurTransaction.commitAllowingStateLoss();
            mCurTransaction = null;
            mFragmentManager.executePendingTransactions();
        } 
    } 
 
    @Override 
    public boolean isViewFromObject(View view, Object object) {
        return ((Fragment)object).getView() == view;
    } 
 
    @Override 
    public Parcelable saveState() {
        Bundle state = null;
        if (mSavedState.size() > 0) {
            state = new Bundle();
            Fragment.SavedState[] fss = new Fragment.SavedState[mSavedState.size()];
6
CodeRank

Related Android FragmentManager Questions & Answers:

Other Android FragmentManager Examples

51:	
52:			if (fragment != null) {
53:				FragmentManager fragmentManager = getFragmentManager();
54:				fragmentManager.beginTransaction()
55:						.replace(R.id.frame_container, fragment).commit();

Read More

187:	
188:			if (fragment != null) {
189:				FragmentManager fragmentManager = getFragmentManager();
190:				fragmentManager.beginTransaction()
191:						.replace(R.id.frame_container, fragment).commit();

Read More

See Code Examples for Android FragmentManager Methods: