Java Code Examples for android.support.v4.app.FragmentTransaction#attach()
The following examples show how to use
android.support.v4.app.FragmentTransaction#attach() .
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: PartFileActivity.java From aMuleRemote with GNU General Public License v3.0 | 6 votes |
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) { FragmentTransaction realFT = getFT(ft); // Check if the fragment is already initialized if (mFragment == null) { // If not, instantiate and add it to the activity mFragment = Fragment.instantiate(mActivity, mClass.getName()); Bundle b = new Bundle(); b.putByteArray(BUNDLE_PARAM_HASH, mHash); mFragment.setArguments(b); //realFT.add(R.id.partfile_tabcontent, mFragment, mTag); // http://stackoverflow.com/questions/9083747/android-ics-actionbar-tabs-orientation-change realFT.replace(R.id.partfile_tabcontent, mFragment, mTag); } else { // If it exists, simply attach it in order to show it realFT.attach(mFragment); } if (ft == null) realFT.commit(); }
Example 2
Source File: NavigationDrawerActivity.java From ZhihuDaily with Apache License 2.0 | 6 votes |
@Override public void onNavigationDrawerItemSelected(int position) { FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); Fragment lastFragment = fragmentManager.findFragmentByTag(getTag(mLastPosition)); if (lastFragment != null) { fragmentTransaction.detach(lastFragment); } Fragment fragment = fragmentManager.findFragmentByTag(getTag(position)); if (fragment == null) { fragment = getFragmentItem(position); fragmentTransaction.add(R.id.container, fragment, getTag(position)); } else { fragmentTransaction.attach(fragment); } fragmentTransaction.commit(); mLastPosition = position; mTitle = mNavigationFragment.getTitle(position); restortActionBar(); }
Example 3
Source File: PullToNextFragmentAdapter.java From Android-PullToNextLayout with Apache License 2.0 | 6 votes |
@Override protected void attachContentView(PullToNextEntity pullToNextView) { FragmentTransaction transaction = fm.beginTransaction(); Fragment f = fm.findFragmentByTag("position" + pullToNextView.getPosition()); if (f != null) { transaction.attach(f); } else { transaction.add(pullToNextView.getContentId(), this.getItem(pullToNextView.getPosition()) , "position" + pullToNextView.getPosition()); } transaction.commitAllowingStateLoss(); this.fm.executePendingTransactions(); }
Example 4
Source File: MainActivity.java From sms-ticket with Apache License 2.0 | 6 votes |
@Override public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) { mSelectedTab = tab.getPosition(); String selectedTag = (mSelectedTab == TAB_TICKETS) ? TAG_TICKETS : TAG_STATS; ProjectBaseFragment preInitializedFragment = (ProjectBaseFragment)getSupportFragmentManager() .findFragmentByTag(selectedTag); if (preInitializedFragment == null) { switch (mSelectedTab) { case TAB_TICKETS: mCurrentFragment = TicketsFragment.newInstance(getIntent().getLongExtra(EXTRA_TICKET_ID, TicketsFragment.NONE), getIntent().getBooleanExtra(EXTRA_SHOW_SMS, false)); break; case TAB_STATISTICS: mCurrentFragment = new StatisticsFragment(); break; } ft.add(android.R.id.content, mCurrentFragment, selectedTag); } else { mCurrentFragment = preInitializedFragment; ft.attach(preInitializedFragment); } }
Example 5
Source File: EnterTreatment.java From HAPP with GNU General Public License v3.0 | 6 votes |
public void refreshListFragments(){ final FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); if (activeTreatmentsFragmentObject.isAdded()) { ft.detach(activeTreatmentsFragmentObject); ft.attach(activeTreatmentsFragmentObject); } if (todayTreatmentsFragmentObject.isAdded()) { ft.detach(todayTreatmentsFragmentObject); ft.attach(todayTreatmentsFragmentObject); } if (yestTreatmentsFragmentObject.isAdded()) { ft.detach(yestTreatmentsFragmentObject); ft.attach(yestTreatmentsFragmentObject); } ft.commit(); }
Example 6
Source File: MainCarActivity.java From carstream-android-auto with Apache License 2.0 | 5 votes |
private void switchToFragment(String tag) { if (tag.equals(mCurrentFragmentTag)) { return; } FragmentManager manager = getSupportFragmentManager(); Fragment currentFragment = mCurrentFragmentTag == null ? null : manager.findFragmentByTag(mCurrentFragmentTag); Fragment newFragment = manager.findFragmentByTag(tag); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); if (currentFragment != null) { transaction.detach(currentFragment); } transaction.attach(newFragment); transaction.commit(); mCurrentFragmentTag = tag; }
Example 7
Source File: RemotesFragment.java From rcloneExplorer with MIT License | 5 votes |
private void refreshFragment() { if (getFragmentManager() == null) { return; } FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); fragmentTransaction.detach(this); fragmentTransaction.attach(this); fragmentTransaction.commit(); }
Example 8
Source File: FragmentPageSnapAdapter.java From RecyclerPager with Apache License 2.0 | 5 votes |
/** * Attach Fragment, */ @Override public void onViewAttachedToWindow(@NonNull FragmentViewHolder holder) { String name = makeFragmentName(holder.itemView.getId(), holder.getAdapterPosition()); Fragment fragment = mFragmentManager.findFragmentByTag(name); if (fragment != null && fragment == holder.currentFragment) { // Nothing Changed } else { FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction(); if (fragment != null) { fragmentTransaction.attach(fragment); } else { fragment = getItem(holder.getAdapterPosition()); fragmentTransaction.add(holder.itemView.getId(), fragment, name); } fragment.setMenuVisibility(false); fragment.setUserVisibleHint(false); fragmentTransaction.commitNowAllowingStateLoss(); if (holder.currentFragment != null && holder.currentFragment.getUserVisibleHint()) { holder.currentFragment.setMenuVisibility(false); holder.currentFragment.setUserVisibleHint(false); } holder.currentFragment = fragment; } }
Example 9
Source File: FragmentRecyclerAdapter.java From RecyclerPager with Apache License 2.0 | 5 votes |
/** * Attach Fragment */ @Override public void onViewAttachedToWindow(@NonNull FragmentViewHolder holder) { String name = makeFragmentName(holder.itemView.getId(), holder.getAdapterPosition()); Fragment fragment = mFragmentManager.findFragmentByTag(name); if (fragment != null && fragment == holder.currentFragment) { // Nothing Changed } else { FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction(); if (fragment != null) { fragmentTransaction.attach(fragment); } else { fragment = getItem(holder.getAdapterPosition()); fragmentTransaction.add(holder.itemView.getId(), fragment, name); } fragmentTransaction.commitNowAllowingStateLoss(); if (holder.currentFragment != null && holder.currentFragment.getUserVisibleHint()) { holder.currentFragment.setMenuVisibility(false); holder.currentFragment.setUserVisibleHint(false); } holder.currentFragment = fragment; if (!fragment.getUserVisibleHint()) { fragment.setMenuVisibility(true); fragment.setUserVisibleHint(true); } } }
Example 10
Source File: FragmentStateManager.java From FragmentStateManager with MIT License | 5 votes |
/** * Shows fragment at position and detaches previous fragment if exists. If fragment is found in * fragment manager, it is reattached else added. * * @param position * @return fragment at position */ public Fragment changeFragment(int position) { String tag = makeFragmentName(container.getId(), getItemId(position)); FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction(); /* If fragment manager doesn't have an instance of the fragment, get an instance and add it to the transaction. Else, attach the instance to transaction. */ Fragment fragment = mFragmentManager.findFragmentByTag(tag); if (fragment == null) { fragment = getItem(position); fragmentTransaction.add(container.getId(), fragment, tag); } else { fragmentTransaction.attach(fragment); } // Detach existing primary fragment Fragment curFrag = mFragmentManager.getPrimaryNavigationFragment(); if (curFrag != null) { fragmentTransaction.detach(curFrag); } // Set fragment as primary navigator for child manager back stack to be handled by system fragmentTransaction.setPrimaryNavigationFragment(fragment); fragmentTransaction.setReorderingAllowed(true); fragmentTransaction.commitNowAllowingStateLoss(); return fragment; }
Example 11
Source File: TwoWayViewActivity.java From UltimateAndroid with Apache License 2.0 | 5 votes |
@Override public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) { mFragment = (LayoutFragment) getSupportFragmentManager().findFragmentByTag(mTag); if (mFragment == null) { mFragment = (LayoutFragment) LayoutFragment.newInstance(mLayoutId); ft.add(R.id.content, mFragment, mTag); } else { ft.attach(mFragment); } mSelectedLayoutId = mFragment.getLayoutId(); }
Example 12
Source File: ArrayPagerAdapter.java From java-n-IDE-for-Android with Apache License 2.0 | 4 votes |
public void attach(Fragment fragment, FragmentTransaction currTransaction) { currTransaction.attach(fragment); }
Example 13
Source File: ScheduleActivity.java From utexas-utilities with Apache License 2.0 | 4 votes |
@Override public void attach(Fragment fragment, FragmentTransaction fragmentTransaction) { fragmentTransaction.attach(fragment); }
Example 14
Source File: BalanceActivity.java From utexas-utilities with Apache License 2.0 | 4 votes |
@Override public void attach(Fragment fragment, FragmentTransaction fragmentTransaction) { fragmentTransaction.attach(fragment); }
Example 15
Source File: MainActivity.java From Androzic with GNU General Public License v3.0 | 4 votes |
private void selectItem(int position) { if (mDrawerAdapter.getSelectedItem() == position) return; DrawerItem item = mDrawerItems.get(position); // Actions if (item.type == DrawerItem.ItemType.INTENT) { if (position > 0) startActivity(item.intent); } // Fragments else if (item.type == DrawerItem.ItemType.FRAGMENT) { FragmentManager fm = getSupportFragmentManager(); if (fm.getBackStackEntryCount() > 0) { fm.popBackStackImmediate(0, FragmentManager.POP_BACK_STACK_INCLUSIVE); } FragmentTransaction ft = fm.beginTransaction(); Fragment parent = fm.findFragmentById(R.id.content_frame); if (parent != null) { ft.detach(parent); } Fragment fragment = fm.findFragmentByTag(item.name); if (fragment != null) { ft.attach(fragment); } else { ft.add(R.id.content_frame, item.fragment, item.name); } ft.commit(); // update selected item and title, then close the drawer updateDrawerUI(item, position); } else if (item.type == DrawerItem.ItemType.ACTION) { Log.e(TAG, "ACTION"); runOnUiThread(item.action); } mDrawerLayout.closeDrawer(mDrawerList); }
Example 16
Source File: ArrayPagerAdapter.java From cwac-pager with Apache License 2.0 | 4 votes |
public void attach(Fragment fragment, FragmentTransaction currTransaction) { currTransaction.attach(fragment); }