Java Code Examples for android.support.v4.app.FragmentManager#beginTransaction()
The following examples show how to use
android.support.v4.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: ImagesActivity.java From android-storage-permissions with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_images); ImagesFragment imagesFragment = (ImagesFragment) getSupportFragmentManager().findFragmentById(R.id.contentframe); if (imagesFragment == null) { imagesFragment = new ImagesFragment(); FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.add(R.id.contentframe, imagesFragment); transaction.commit(); } mView = imagesFragment; mPresenter = new ImagesPresenter(Injection.getImageRepository(this), mView); }
Example 2
Source File: LetvBaseWebViewActivity.java From letv with Apache License 2.0 | 6 votes |
public void onJsShareDialogShow(String jsonString) { FragmentManager fm = getSupportFragmentManager(); if (fm != null) { FragmentTransaction ft = fm.beginTransaction(); if (this.mInviteShareProtocol == null) { LeResponseMessage response = LeMessageManager.getInstance().dispatchMessage(new LeMessage(LeMessageIds.MSG_SHARE_INVITE_WEBVIEW_INIT)); if (LeResponseMessage.checkResponseMessageValidity(response, WebViewInviteShareProtocol.class)) { this.mInviteShareProtocol = (WebViewInviteShareProtocol) response.getData(); } } else { ft.remove(this.mInviteShareProtocol.getFragment()); } if (this.mInviteShareProtocol != null) { this.mInviteShareProtocol.setShareText(jsonString); ft.add(this.mInviteShareProtocol.getFragment(), "shareDialogs"); ft.commitAllowingStateLoss(); } } }
Example 3
Source File: VipOrderDetailActivity.java From letv with Apache License 2.0 | 6 votes |
@TargetApi(17) private void showAlipayDialog(boolean notOpenFlag) { FragmentManager fm = getSupportFragmentManager(); if (fm != null && getActivity() != null && !getActivity().isDestroyed()) { FragmentTransaction ft = fm.beginTransaction(); this.mAlipayAutoPayDialog = (AlipayAutoPayDialog) fm.findFragmentByTag("showmAlipayPayDialog"); Bundle bundle = new Bundle(); bundle.putBoolean(AlipayConstant.NOT_OPEN_CONTINUE_MONTHLY, notOpenFlag); bundle.putBoolean(AlipayConstant.IS_MOBILE_VIP_FLAG, this.mIsMobileVipFlag); if (this.mAlipayAutoPayDialog == null) { this.mAlipayAutoPayDialog = new AlipayAutoPayDialog(); } else { ft.remove(this.mAlipayAutoPayDialog); } this.mAlipayAutoPayDialog.setAlipayConfirmCallback(this); if (this.mAlipayAutoPayDialog.getArguments() == null) { this.mAlipayAutoPayDialog.setArguments(bundle); } ft.add(this.mAlipayAutoPayDialog, "showmAlipayPayDialog"); ft.commitAllowingStateLoss(); } }
Example 4
Source File: MainActivityFragment.java From Android-animated-toolbar with MIT License | 5 votes |
public static void load(final FragmentManager fragmentManager, final Boolean toBackStack) { FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.container, new MainActivityFragment()); if (toBackStack) { fragmentTransaction.addToBackStack(FRAGMENT_NAME); } fragmentTransaction.commit(); }
Example 5
Source File: EarthquakeMainActivity.java From Wrox-ProfessionalAndroid-4E with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_earthquake_main); FragmentManager fm = getSupportFragmentManager(); // Android will automatically re-add any Fragments that // have previously been added after a configuration change, // so only add it if this isn't an automatic restart. if (savedInstanceState == null) { FragmentTransaction ft = fm.beginTransaction(); mEarthquakeListFragment = new EarthquakeListFragment(); ft.add(R.id.main_activity_frame, mEarthquakeListFragment, TAG_LIST_FRAGMENT); ft.commitNow(); } else { mEarthquakeListFragment = (EarthquakeListFragment) fm.findFragmentByTag(TAG_LIST_FRAGMENT); } // Retrieve the Earthquake View Model for this Activity. earthquakeViewModel = ViewModelProviders.of(this) .get(EarthquakeViewModel.class); }
Example 6
Source File: SecondActivity.java From YCShopDetailLayout with Apache License 2.0 | 5 votes |
private void initShopMainFragment() { FragmentManager fm = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fm.beginTransaction(); if(shopMainFragment==null){ shopMainFragment = new ShopMain1Fragment(); fragmentTransaction .replace(R.id.fl_shop_main2, shopMainFragment) .commit(); }else { fragmentTransaction.show(shopMainFragment); } }
Example 7
Source File: OtherAppsFragment.java From candybar-library with Apache License 2.0 | 5 votes |
public static void showOtherAppsDialog(@NonNull FragmentManager fm) { FragmentTransaction ft = fm.beginTransaction(); Fragment prev = fm.findFragmentByTag(TAG); if (prev != null) { ft.remove(prev); } try { DialogFragment dialog = OtherAppsFragment.newInstance(); dialog.show(ft, TAG); } catch (IllegalStateException | IllegalArgumentException ignored) {} }
Example 8
Source File: ActionBarFragmentMenu.java From V.FlyoutTest with MIT License | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true); FragmentManager fm = getChildFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); mFragment3 = (Menu3Fragment)fm.findFragmentByTag("f3"); if (mFragment3 == null) { mFragment3 = new Menu3Fragment(); ft.add(mFragment3, "f3"); } ft.commit(); }
Example 9
Source File: EarthquakeMainActivity.java From Wrox-ProfessionalAndroid-4E with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_earthquake_main); FragmentManager fm = getSupportFragmentManager(); // Android will automatically re-add any Fragments that // have previously been added after a configuration change, // so only add it if this isn't an automatic restart. if (savedInstanceState == null) { FragmentTransaction ft = fm.beginTransaction(); mEarthquakeListFragment = new EarthquakeListFragment(); ft.add(R.id.main_activity_frame, mEarthquakeListFragment, TAG_LIST_FRAGMENT); ft.commitNow(); } else { mEarthquakeListFragment = (EarthquakeListFragment)fm.findFragmentByTag(TAG_LIST_FRAGMENT); } Date now = Calendar.getInstance().getTime(); List<Earthquake> dummyQuakes = new ArrayList<Earthquake>(0); dummyQuakes.add(new Earthquake("0", now, "San Jose", null, 7.3, null)); dummyQuakes.add(new Earthquake("1", now, "LA", null, 6.5, null)); mEarthquakeListFragment.setEarthquakes(dummyQuakes); }
Example 10
Source File: ActivityUtils.java From CoreModule with Apache License 2.0 | 5 votes |
/** * 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) { FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.add(frameId, fragment); transaction.commit(); }
Example 11
Source File: FragmentHelper.java From OmniList with GNU Affero General Public License v3.0 | 5 votes |
private static void replace(AppCompatActivity activity, Fragment fragment, @IdRes int containerId, boolean backStack) { if (activity.isFinishing()) return; FragmentManager fragmentManager = activity.getSupportFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); setCustomAnimations(transaction); if (backStack) transaction.addToBackStack(null); transaction.replace(containerId, fragment).commit(); }
Example 12
Source File: ActivityUtils.java From AndroidProjects with MIT License | 5 votes |
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 13
Source File: MainActivity.java From flickabledialog with MIT License | 5 votes |
private void setDefaultFragment(){ FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.tab_content_container, new CreateMailFragment()); fragmentTransaction.commit(); }
Example 14
Source File: MapFragment.java From droidkaigi2016 with Apache License 2.0 | 5 votes |
@Override public void onDestroyView() { FragmentManager fm = getChildFragmentManager(); SupportMapFragment map = (SupportMapFragment) fm.findFragmentById(R.id.map); FragmentTransaction ft = fm.beginTransaction(); ft.remove(map); ft.commitAllowingStateLoss(); super.onDestroyView(); }
Example 15
Source File: IntentChooserFragment.java From candybar-library with Apache License 2.0 | 5 votes |
public static void showIntentChooserDialog(@NonNull FragmentManager fm, int type) { FragmentTransaction ft = fm.beginTransaction(); Fragment prev = fm.findFragmentByTag(TAG); if (prev != null) { ft.remove(prev); } try { DialogFragment dialog = IntentChooserFragment.newInstance(type); dialog.show(ft, TAG); } catch (IllegalArgumentException | IllegalStateException ignored) {} }
Example 16
Source File: ActivityUtil.java From ClassSchedule with Apache License 2.0 | 5 votes |
/** * */ public static void replaceFragmentToActivity(@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment, int frameId) { checkNotNull(fragmentManager, ""); checkNotNull(fragment, ""); FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.replace(frameId, fragment); transaction.commit(); }
Example 17
Source File: MainActivity.java From openshop.io-android with MIT License | 5 votes |
/** * Add first fragment to the activity. This fragment will be attached to the bottom of the fragments stack. * When fragment stack is cleared {@link #clearBackStack}, this fragment will be shown. */ private void addInitialFragment() { Fragment fragment = new BannersFragment(); FragmentManager frgManager = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = frgManager.beginTransaction(); fragmentTransaction.add(R.id.main_content_frame, fragment).commit(); frgManager.executePendingTransactions(); }
Example 18
Source File: BaseActivity.java From News with Apache License 2.0 | 4 votes |
protected void addFragment(FragmentManager fragmentManager, int containerId, Fragment fragment) { FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.add(containerId, fragment); fragmentTransaction.commit(); }
Example 19
Source File: DialogHelper.java From AcDisplay with GNU General Public License v2.0 | 4 votes |
private static void showDialog(@NonNull AppCompatActivity activity, @NonNull DialogFragment fragment, @NonNull String tag) { Check.getInstance().isInMainThread(); FragmentManager fm = activity.getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); Fragment prev = fm.findFragmentByTag(tag); if (prev != null) ft.remove(prev); ft.addToBackStack(null); fragment.show(ft, tag); }
Example 20
Source File: SupportFragmentTransactionBuilder.java From SafelyAndroid with MIT License | 4 votes |
public static SupportFragmentTransactionBuilder transaction(FragmentManager fragmentManager) { return new SupportFragmentTransactionBuilder(fragmentManager, fragmentManager.beginTransaction()); }