Android FragmentTransaction - 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 FragmentTransaction class.

This code example shows how to use the following methods:addToBackStack, remove
 
        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 {
 
        private static final String VERSION_UNAVAILABLE = "N/A";
 
        public AboutDialog() { 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:add, attach
//        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);
//            mCurTransaction.add(container.getId(), fragment, 
//                    makeFragmentName(container.getId(), itemId)); 
            mCurTransaction.add(container.getId(), fragment,
                    getTag(position));
        } 
        if (fragment != mCurrentPrimaryItem) {
            fragment.setMenuVisibility(false);
            fragment.setUserVisibleHint(false);
        } 
 
        return fragment;
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:add
        } 
 
        public void onTabSelected(Tab tab, FragmentTransaction ft) {
            if (mFragment == null) {
                mFragment = Fragment.instantiate(mActivity, mClass.getName(), mArgs);
                ft.add(android.R.id.content, mFragment, mTag);
            } else { 
                ft.attach(mFragment);
            } 
        } 
 
        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
            if (mFragment != null) {
                ft.detach(mFragment);
            } 
        } 
 
        public void onTabReselected(Tab tab, FragmentTransaction ft) {
            Toast.makeText(mActivity, "Reselected!", Toast.LENGTH_SHORT).show();
        } 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:replace
  private void showSimple(FragmentTransaction ft) {
    if (simple == null) {
      simple=new EndlessAdapterFragment();
    } 
 
    ft.replace(android.R.id.content, simple);
  } 
 
  private void showCustom(FragmentTransaction ft) {
    if (customTask == null) {
      customTask=new EndlessAdapterCustomTaskFragment();
    } 
 
    ft.replace(android.R.id.content, customTask);
  } 
 
  private static enum Tabs { 
    TAB_SIMPLE, TAB_CUSTOM_TASK;
  } 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:addToBackStack, remove
                                  @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) {
        final android.support.v4.app.FragmentTransaction ft = fm.beginTransaction();
 
        android.support.v4.app.Fragment prev = fm.findFragmentByTag(fragmentTag);
        if (prev != null) {
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:add, attach
		// 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,
					makeFragmentName(container.getId(), itemId));
		} 
		// if (fragment != mCurrentPrimaryItem) { 
		setMenuVisibility(fragment, false);
		setUserVisibleHint(fragment, false);
		// } 
 
		return fragment;
	} 
 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:add, commit
 
		if (savedInstanceState == null) {
			Fragment f = new SampleFragment();
			FragmentManager fm = getFragmentManager();
			FragmentTransaction ft = fm.beginTransaction();
			ft.add(android.R.id.primary, f);
			ft.commit();
		} 
	} 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:add, attach
This code example shows how to use the following methods:hide
    protected static void showFragment(FragmentTransaction ft, Fragment f) {
        if ((f != null) && f.isHidden()) ft.show(f);
    } 
 
    protected static void hideFragment(FragmentTransaction ft, Fragment f) {
        if ((f != null) && !f.isHidden()) ft.hide(f);
    } 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:hide
		 
	} 
 
	@Override 
	public void onTabUnselected(Tab tab, FragmentTransaction ft) {
		ft.hide(this);
		 
	} 
	 
	/////////////////////////////////////////////////////////////////////////////// 
	// Implementation of SetData 
	/////////////////////////////////////////////////////////////////////////////// 
 
	@Override 
	public void setData(Bundle data) {
		// Display the string spelling out the number 
		EditText t = (EditText) getActivity().findViewById(R.id.detail_text);
		String s = data.getString("placeName");
		t.setText(s);		
	} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Android FragmentTransaction Questions & Answers:

Other Android FragmentTransaction Examples

62:	
63:		@Override
64:		public void onTabReselected(Tab tab, FragmentTransaction ft) {
65:		}
66:	
-
66:	
67:		@Override
68:		public void onTabSelected(Tab tab, FragmentTransaction ft) {
69:			// on tab selected
70:			// show respected fragment view
-
73:	
74:		@Override
75:		public void onTabUnselected(Tab tab, FragmentTransaction ft) {
76:		}
77:

Read More

See Code Examples for Android FragmentTransaction Methods: