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

The following examples show how to use android.app.FragmentManager#beginTransaction() . 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
Source File: TVDemoActivity.java    From BuildingForAndroidTV with 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 2
Source File: GalleryList.java    From moviedb-android with 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 3
Source File: CameraPreview.java    From cordova-plugin-camera-preview with MIT License 6 votes vote down vote up
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 4
Source File: FragmentReplacementActivity.java    From HelloActivityAndFragment with Apache License 2.0 6 votes vote down vote up
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 5
Source File: HtmlDialog.java    From HtmlDialog with 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
Source File: SettingActivity.java    From NetEasyNews with GNU General Public License v3.0 6 votes vote down vote up
@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 7
Source File: MainActivity.java    From Android-Basics-Codes with Artistic License 2.0 6 votes vote down vote up
@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
Source File: MapsAppActivity.java    From maps-app-android with Apache License 2.0 6 votes vote down vote up
/**
 * 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 9
Source File: RootsFragment.java    From FireFiles with 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 10
Source File: GilgaMeshActivity.java    From gilgamesh with GNU General Public License v3.0 5 votes vote down vote up
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 11
Source File: ActivityUtils.java    From 361Camera with 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 12
Source File: IRKitVirtualDeviceListActivity.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * 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 13
Source File: MirrorActivity.java    From mirror with 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 14
Source File: GilgaMeshActivity.java    From gilgamesh with GNU General Public License v3.0 5 votes vote down vote up
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 File: RootsFragment.java    From FireFiles with 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 16
Source File: HelpUtils.java    From BetterWeather with 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 17
Source File: MainActivity.java    From Android-Basics-Codes with Artistic License 2.0 5 votes vote down vote up
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 18
Source File: SearchFragment.java    From android-spotify-demo with 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 19
Source File: RTProxyImpl.java    From memoir with 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 20
Source File: HomeFragment.java    From FireFiles with 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();
}