Java Code Examples for android.app.FragmentManager#beginTransaction()

The following examples show how to use android.app.FragmentManager#beginTransaction() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private void replaceFragmentAWithB() {
    FragmentManager fragmentManager = getFragmentManager();
    Fragment fragment = fragmentManager.findFragmentByTag(FragmentB.TAG);
    if (null == fragment) {
        FragmentB fragmentB = new FragmentB();
        Log.i(LOG_TAG, "do add fragmentB action");
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.replace_container, fragmentB, FragmentB.TAG)
                .addToBackStack(FragmentB.TAG)
                .commit();

        // if we replace() without addToBackStack(), FragmentA will destroyed and detach.
        // But then remove FragmentB, A's view is still shown, although A is destroyed.

        // if we replace() with addToBackStack(), FragmentA will go till onDestroyView()
        // when back pressed, FragmentB will be detached, and A will resume.
    }
}
 
Example 2
Source Project: BuildingForAndroidTV   File: TVDemoActivity.java    License: MIT License 6 votes vote down vote up
@Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_custom);

	headersFragment = new CustomHeadersFragment();
	rowsFragment = new CustomRowsFragment();

	FragmentManager fragmentManager = getFragmentManager();
	FragmentTransaction transaction = fragmentManager.beginTransaction();
	transaction
		.replace(R.id.header_container, headersFragment, "CustomHeadersFragment")
		.replace(R.id.rows_container, rowsFragment, "CustomRowsFragment");
	transaction.commit();

	fragments = new LinkedHashMap<Integer, CustomRowsFragment>();

	for (int i = 0; i < CATEGORIES_NUMBER; i++) {
		CustomRowsFragment fragment = new CustomRowsFragment();
		fragments.put(i, fragment);
	}
}
 
Example 3
Source Project: moviedb-android   File: GalleryList.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Callback method to be invoked when an item in this AdapterView has been clicked.
 *
 * @param parent   The AdapterView where the click happened.
 * @param view     The view within the AdapterView that was clicked (this will be a view provided by the adapter)
 * @param position The position of the view in the adapter.
 * @param id       The row id of the item that was clicked.
 */
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
                        long id) {
    FragmentManager manager = getFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();
    Bundle args = new Bundle();
    args.putStringArrayList("galleryList", galleryPath);
    args.putInt("currPos", position);
    galleryPreview.setArguments(args);
    transaction.replace(R.id.frame_container, galleryPreview);
    // add the current transaction to the back stack:
    transaction.addToBackStack("galleryList");
    transaction.commit();

}
 
Example 4
private boolean stopCamera(CallbackContext callbackContext) {
  if(webViewParent != null) {
    cordova.getActivity().runOnUiThread(new Runnable() {
      @Override
      public void run() {
        ((ViewGroup)webView.getView()).bringToFront();
        webViewParent = null;
      }
    });
  }

  if(this.hasView(callbackContext) == false){
    return true;
  }

  FragmentManager fragmentManager = cordova.getActivity().getFragmentManager();
  FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
  fragmentTransaction.remove(fragment);
  fragmentTransaction.commit();
  fragment = null;

  callbackContext.success();
  return true;
}
 
Example 5
Source Project: HtmlDialog   File: HtmlDialog.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * The sole constructor for {@code HtmlDialog}.
 *
 * @param fm  The {@code FragmentManager} from the calling activity that is used
 *            internally to show the {@code DialogFragment}.
 */
public HtmlDialog(FragmentManager fm)
{
    // See if there are any DialogFragments from the FragmentManager
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag(HtmlDialogFragment.TAG_HTML_DIALOG_FRAGMENT);

    // Remove if found
    if (prev != null)
    {
        ft.remove(prev);
        ft.commit();
    }

    mFragmentManager = fm;
}
 
Example 6
/**
 * Opens the content browser that shows the user's maps.
 */
private void showContentBrowser() {
	FragmentManager fragmentManager = getFragmentManager();
	Fragment browseFragment = fragmentManager.findFragmentByTag(ContentBrowserFragment.TAG);
	if (browseFragment == null) {
		browseFragment = new ContentBrowserFragment();
	}

	if (!browseFragment.isVisible()) {
		FragmentTransaction transaction = fragmentManager.beginTransaction();
		transaction.add(R.id.maps_app_activity_content_frame, browseFragment, ContentBrowserFragment.TAG);
		transaction.addToBackStack(null);
		transaction.commit();

		invalidateOptionsMenu(); // reload the options menu
	}

	mDrawerLayout.closeDrawers();
}
 
Example 7
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
  //1.����Fragment����
    fragment01 = new Fragment01();
	//2.��ȡFragment������
	FragmentManager fm = getFragmentManager();
	//3.������
	FragmentTransaction ft = fm.beginTransaction();
	//4.������ʾfragment01
	//arg0:������id��Ҳ����֡����
	ft.replace(R.id.fl, fragment01);
	//5.�ύ
	ft.commit();
}
 
Example 8
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_setting);
    Toolbar my_toolbar = (Toolbar) findViewById(R.id.my_toolbar);
    initToolbar();

    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    SettingFragment settingFragment = new  SettingFragment();
    fragmentTransaction.replace(R.id.id_content, settingFragment);
    fragmentTransaction.commit();


}
 
Example 9
Source Project: memoir   File: RTProxyImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
/* @inheritDoc */
   public void openDialogFragment(String fragmentTag, DialogFragment fragment) {
       Activity activity = getActivity();
       if (activity != null) {
           FragmentManager fragmentMgr = activity.getFragmentManager();
           FragmentTransaction ft = fragmentMgr.beginTransaction();
           DialogFragment oldFragment = (DialogFragment) fragmentMgr
                   .findFragmentByTag(fragmentTag);
           if (oldFragment == null) {
               fragment.show(ft, fragmentTag);
           }
       }
   }
 
Example 10
Source Project: android-spotify-demo   File: SearchFragment.java    License: MIT License 5 votes vote down vote up
@SuppressLint("ResourceType")
public static SearchFragment getFragmentInstance(FragmentManager fm, String tag){
    SearchFragment fragment = (SearchFragment)fm.findFragmentByTag(tag);

    if(fragment == null){
        fragment = new SearchFragment();

        FragmentTransaction ft = fm.beginTransaction();
        ft.replace(R.id.fragment, fragment, tag).commitAllowingStateLoss();
    }
    return fragment;
}
 
Example 11
public void click2(View v){
	//��ʾfragment02
	//1.����Fragment����
	Fragment02 fragment02 = new Fragment02();
	//2.��ȡFragment������
	FragmentManager fm = getFragmentManager();
	//3.������
	FragmentTransaction ft = fm.beginTransaction();
	//4.������ʾfragment02
	//arg0:������id��Ҳ����֡����
	ft.replace(R.id.fl, fragment02);
	//5.�ύ
	ft.commit();
}
 
Example 12
Source Project: BetterWeather   File: HelpUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static void showAboutDialog(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");
}
 
Example 13
Source Project: FireFiles   File: RootsFragment.java    License: Apache License 2.0 5 votes vote down vote up
public static void show(FragmentManager fm, Intent includeApps) {
    final Bundle args = new Bundle();
    args.putParcelable(EXTRA_INCLUDE_APPS, includeApps);

    final RootsFragment fragment = new RootsFragment();
    fragment.setArguments(args);

    final FragmentTransaction ft = fm.beginTransaction();
    ft.replace(R.id.container_roots, fragment);
    ft.commitAllowingStateLoss();
}
 
Example 14
private void showInfo ()
{
 FragmentManager fm = getFragmentManager();
 FragmentTransaction ft = fm.beginTransaction();
 ft.hide(fm.findFragmentById(R.id.status_list));
 ft.show(fm.findFragmentById(R.id.info_screen));
 ft.hide(fm.findFragmentById(R.id.device_list));
 
  ft.commit();
}
 
Example 15
Source Project: mirror   File: MirrorActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void showDialogFragment(final FragmentManager fragmentManager,
                                final DialogFragment dialogFragment,
                                final boolean addToBackStack,
                                final String tag) {
    final FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.add(dialogFragment, tag);
    if (addToBackStack) {
        transaction.addToBackStack(tag);
    }
    transaction.commitAllowingStateLoss();
}
 
Example 16
/**
 * Fragment の遷移.
 * @param f Fragment
 */
private void moveFragment(final Fragment f) {
    FragmentManager fm = getFragmentManager();
    FragmentTransaction t = fm.beginTransaction();
    t.setTransition(FragmentTransaction.TRANSIT_NONE);
    t.replace(android.R.id.content, f);
    t.addToBackStack(null);
    t.commit();
}
 
Example 17
Source Project: 361Camera   File: ActivityUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * The {@code fragment} is added to the container view with id {@code frameId}. The operation is
 * performed by the {@code fragmentManager}.
 */
public static void addFragmentToActivity(@NonNull FragmentManager fragmentManager,
                                         @NonNull Fragment fragment, int frameId) {
    checkNotNull(fragmentManager);
    checkNotNull(fragment);
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.add(frameId, fragment);
    transaction.commit();
}
 
Example 18
private void showNearby ()
{
 FragmentManager fm = getFragmentManager();
 FragmentTransaction ft = fm.beginTransaction();
 ft.hide(fm.findFragmentById(R.id.status_list));
 ft.hide(fm.findFragmentById(R.id.info_screen));
 ft.show(fm.findFragmentById(R.id.device_list));
 
  ft.commit();
}
 
Example 19
Source Project: FireFiles   File: RootsFragment.java    License: Apache License 2.0 5 votes vote down vote up
public static void show(FragmentManager fm, Intent includeApps) {
    final Bundle args = new Bundle();
    args.putParcelable(EXTRA_INCLUDE_APPS, includeApps);

    final RootsFragment fragment = new RootsFragment();
    fragment.setArguments(args);

    final FragmentTransaction ft = fm.beginTransaction();
    ft.replace(R.id.container_roots, fragment);
    ft.commitAllowingStateLoss();
}
 
Example 20
Source Project: FireFiles   File: HomeFragment.java    License: Apache License 2.0 4 votes vote down vote up
public static void show(FragmentManager fm) {
    final HomeFragment fragment = new HomeFragment();
    final FragmentTransaction ft = fm.beginTransaction();
    ft.replace(R.id.container_directory, fragment, TAG);
    ft.commitAllowingStateLoss();
}