Example usage for android.support.v4.app FragmentTransaction detach

List of usage examples for android.support.v4.app FragmentTransaction detach

Introduction

In this page you can find the example usage for android.support.v4.app FragmentTransaction detach.

Prototype

public abstract FragmentTransaction detach(Fragment fragment);

Source Link

Document

Detach the given fragment from the UI.

Usage

From source file:org.openbmap.utils.TabManager.java

@Override
public void onTabChanged(final String tabId) {
    final TabInfo newTab = mTabs.get(tabId);
    if (mLastTab != newTab) {
        final FragmentTransaction ft = mActivity.getSupportFragmentManager().beginTransaction();
        if (mLastTab != null) {
            if (mLastTab.fragment != null) {
                ft.detach(mLastTab.fragment);
            }//from  ww w.  j  av a2s.  c  o m
        }
        if (newTab != null) {
            if (newTab.fragment == null) {
                newTab.fragment = Fragment.instantiate(mActivity, newTab.clss.getName(), newTab.args);
                ft.add(mContainerId, newTab.fragment, newTab.tag);
            } else {
                ft.attach(newTab.fragment);
            }
        }

        mLastTab = newTab;
        ft.commit();
        mActivity.getSupportFragmentManager().executePendingTransactions();
    }
}

From source file:org.openmrs.client.activities.PatientDashboardActivity.java

private void recreateFragmentView(final Fragment fragment) {
    FragmentTransaction fragTransaction = getSupportFragmentManager().beginTransaction();
    fragTransaction.detach(fragment);
    fragTransaction.attach(fragment);//w  w w.j a v a 2  s.  co m
    fragTransaction.commit();
}

From source file:com.cse3310.phms.ui.fragments.EStorageFragment.java

public void onEvent(Events.SwitchTabEvent event) {
    populateCardLists();/*  w w  w  .  j a  va 2  s . c  o  m*/

    if (mCardListFragment != null) {
        mCardListFragment.clearCards();
    }

    if (event.position == 0) {
        mCardListFragment.addCards(mHealthCardList);
    } else if (event.position == 1) {
        mCardListFragment.addCards(mRecipeCardList);
    } else {
        mCardListFragment.addCards(mDietCardList);
    }

    FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
    transaction.detach(mCardListFragment);
    transaction.attach(mCardListFragment);
    transaction.commit();
}

From source file:edu.mit.mobile.android.livingpostcards.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    setTitle(""); // as we use the logo
    super.onCreate(savedInstanceState);

    if (savedInstanceState != null) {
        mSavedCurrentTab = savedInstanceState.getInt(INSTANCE_CURRENT_TAB, NO_SAVED_TAB);
    }/*from   w  w  w  .  j  av  a 2s.  c  om*/

    final FragmentManager fm = getSupportFragmentManager();

    // start off with any fragments in a detached state
    final Fragment f = fm.findFragmentById(android.R.id.content);
    if (f != null && !f.isDetached()) {
        final FragmentTransaction ft = fm.beginTransaction();
        ft.detach(f);
        ft.commit();
    }
}

From source file:com.snippet.app.ActionBarCompatActivity.java

@Override
public void onTabChanged(final String tag) {
    TabInfo newTab = this.mapTabInfo.get(tag);
    if (mLastTab != newTab) {
        FragmentTransaction ft = this.getSupportFragmentManager().beginTransaction();
        if (mLastTab != null) {
            if (mLastTab.mFragment != null) {
                ft.detach(mLastTab.mFragment);
            }//ww  w.  java  2 s .co  m
        }
        if (newTab != null) {
            if (newTab.mFragment == null) {
                newTab.mFragment = Fragment.instantiate(this, newTab.mClass.getName(), newTab.mArgs);
                ft.add(R.id.realtabcontent, newTab.mFragment, newTab.mTag);
            } else {
                ft.attach(newTab.mFragment);
            }
        }

        mLastTab = newTab;
        ft.commit();
        this.getSupportFragmentManager().executePendingTransactions();
    }
}

From source file:dat255.grupp06.bibbla.fragments.ProfileFragment.java

@Override
public void onDestroyView() {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.detach(reservationsList);
    fragmentTransaction.detach(loansList);
    fragmentTransaction.commit();// w  ww .  j  a va  2  s . c o m
    super.onDestroyView();
}

From source file:dat255.grupp06.bibbla.fragments.ProfileFragment.java

public void toggleLoans() {
    FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
    ft.detach(reservationsList);
}

From source file:com.arcgis.android.samples.geometrysample.GeometrySampleActivity.java

public void onArticleSelected(int position) {

    FragmentTransaction fragTransaction = getSupportFragmentManager().beginTransaction();

    if (bufferFrag != null && !bufferFrag.isDetached()) {

        fragTransaction.detach(bufferFrag);
        bufferFrag = null;//from   ww  w.  ja  v  a  2s  .c om
    }

    if (uniondiffFrag != null && !uniondiffFrag.isDetached()) {

        fragTransaction.detach(uniondiffFrag);
        uniondiffFrag = null;
    }

    if (spatialrelationFrag != null && !spatialrelationFrag.isDetached()) {

        fragTransaction.detach(spatialrelationFrag);
        spatialrelationFrag = null;
    }

    switch (position) {
    case 0:

        if (bufferFrag == null || bufferFrag.getShownIndex() != position) {
            // Make new fragment to show this selection.
            bufferFrag = BufferFragment.newInstance(position);

            // Execute a transaction, replacing any existing fragment
            // with this one inside the frame.

            fragTransaction.add(R.id.sample_fragment, bufferFrag);

            fragTransaction.setTransition(FragmentTransaction.TRANSIT_NONE);
            fragTransaction.commit();
        }

        break;

    case 1:

        if (uniondiffFrag == null || uniondiffFrag.getShownIndex() != position) {
            // Make new fragment to show this selection.
            uniondiffFrag = UnionDifferenceFragment.newInstance(position);

            // Execute a transaction, replacing any existing fragment
            // with this one inside the frame.

            fragTransaction.add(R.id.sample_fragment, uniondiffFrag);

            fragTransaction.setTransition(FragmentTransaction.TRANSIT_NONE);
            fragTransaction.commit();
        }

        break;

    case 2:

        if (spatialrelationFrag == null || spatialrelationFrag.getShownIndex() != position) {
            // Make new fragment to show this selection.
            spatialrelationFrag = SpatialRelationshipsFragment.newInstance(position);

            // Execute a transaction, replacing any existing fragment
            // with this one inside the frame.

            fragTransaction.add(R.id.sample_fragment, spatialrelationFrag);

            fragTransaction.setTransition(FragmentTransaction.TRANSIT_NONE);
            fragTransaction.commit();
        }

        break;

    default:
        break;

    }
}

From source file:com.HumanDecisionSupportSystemsLaboratory.DD_P2P.ToAddJustificationDialog.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    Bundle b = getArguments();/*from   www .j  a  v a2s . c om*/
    String motion_LID = b.getString(Motion.M_MOTION_LID);
    type = b.getString(Motion.M_MOTION_CHOICE);
    jLID = b.getString(Motion.J_JUSTIFICATION_LID);
    scnt = b.getString(Motion.M_MOTION_ID);

    if (motion_LID != null) {
        crt_motion = D_Motion.getMotiByLID(motion_LID, false, false);
        if (crt_motion != null) {
            if (jLID != null) {
                crt_justification = new JustificationSupportEntry(jLID, Util.ival(scnt, 0));
                init(crt_motion, crt_justification, type);
            } else {
                init(crt_motion, type);
            }
        }
    }
    View view = inflater.inflate(R.layout.dialog_to_add_justification, container);
    final Button butYes = (Button) view.findViewById(R.id.dialog_add_new_justification);
    final Button butNo = (Button) view.findViewById(R.id.do_not_add_new_justification);

    getDialog().setTitle("Justification");

    // add a new justification
    butYes.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            D_Constituent myself = Identity.getCrtConstituent(oLID);
            if (myself == null) {
                Toast.makeText(getActivity(), "Fill your Profile!", Toast.LENGTH_LONG);
                return;
            }
            Intent i = new Intent();
            i.setClass(getActivity(), AddJustification.class);
            Bundle b = new Bundle();
            b.putString(Motion.M_MOTION_CHOICE, ToAddJustificationDialog.this.type);
            b.putString(Motion.M_MOTION_LID, ToAddJustificationDialog.this.crt_motion.getLIDstr());
            String jLID = "";
            if (ToAddJustificationDialog.this.crt_justification != null)
                jLID = ToAddJustificationDialog.this.crt_justification.getJustification_LIDstr();
            b.putString(Motion.J_JUSTIFICATION_LID, jLID);
            i.putExtras(b);
            startActivity(i);
            FragmentTransaction ft = getFragmentManager().beginTransaction();
            ft.detach(ToAddJustificationDialog.this);
            ft.commit();
            Toast.makeText(getActivity(), "Add a new justification", Toast.LENGTH_SHORT).show();
        }
    });

    // if not add a new justification
    butNo.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            D_Constituent myself = Identity.getCrtConstituent(oLID);
            if (myself == null) {
                Toast.makeText(getActivity(), "Fill your Profile!", Toast.LENGTH_LONG);
                return;
            }
            D_Justification j = null;
            if (ToAddJustificationDialog.this.crt_justification != null)
                j = D_Justification.getJustByLID(
                        ToAddJustificationDialog.this.crt_justification.getJustification_LIDstr(), true, false);
            D_Vote vote = D_Vote.createVote(crt_motion, j, type);
            if (DEBUG)
                Log.d("VOTE", "Bad vote=" + vote);

            // D_Vote vote = new D_Vote();
            // vote.setMotionAndOrganizationAll(crt_motion);
            // if (ToAddJustificationDialog.this.crt_justification != null)
            // {
            // D_Justification j =
            // D_Justification.getJustByLID(ToAddJustificationDialog.this.crt_justification.getJustification_LIDstr(),
            // true, false);
            // if (j != null) vote.setJustificationAll(j);
            // }
            // vote.setConstituentAll(Identity.getCrtConstituent(crt_motion.getOrganizationLID()));
            // String choice = type;
            // Log.d("VOTE", "Sign type="+type);
            // vote.setChoice(choice);
            // Log.d("VOTE", "Sign oLID="+crt_motion.getOrganizationLID());
            //
            // Log.d("VOTE", "Sign oLID="+vote);
            // vote.sign();
            // try {
            // vote.storeVerified();
            // } catch (P2PDDSQLException e) {
            // e.printStackTrace();
            // }

            FragmentTransaction ft = getFragmentManager().beginTransaction();
            ft.detach(ToAddJustificationDialog.this);
            ft.commit();

            Intent intent = getActivity().getIntent();
            getActivity().finish();
            startActivity(intent);
        }
    });

    return view;
}

From source file:com.opensource.slidingmenu.utils.FragmentUtil.java

/**
 * Open a fragment/*from  ww w  .  j ava 2 s .c  om*/
 * @param cls
 * @param args
 */
public void openFragment(Class<? extends Fragment> cls, Bundle args) {
    Fragment fragment = mFragmentManager.findFragmentByTag(cls.getName());
    FragmentTransaction ft = mFragmentManager.beginTransaction();
    if (fragment == null) {
        fragment = Fragment.instantiate(mActivity, cls.getName(), args);
        ft.add(mBody, fragment, cls.getName());
    } else {
        if (!fragment.isDetached()) {
            ft.detach(fragment);
        }
        ft.attach(fragment);
    }
    ft.commit();
}