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:de.tap.easy_xkcd.fragments.overview.OverviewBaseFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_overview_style:
        android.support.v7.app.AlertDialog.Builder mDialog = new android.support.v7.app.AlertDialog.Builder(
                getActivity());/* w  w  w . ja  va  2s . c o m*/
        mDialog.setTitle(R.string.overview_style_title).setSingleChoiceItems(R.array.overview_style,
                prefHelper.getOverviewStyle(), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        prefHelper.setOverviewStyle(i);
                        dialogInterface.dismiss();
                        FragmentTransaction transaction = getActivity().getSupportFragmentManager()
                                .beginTransaction();
                        transaction.detach(
                                getActivity().getSupportFragmentManager().findFragmentByTag(OVERVIEW_TAG));
                        switch (i) {
                        case 0:
                            transaction.add(R.id.flContent, new OverviewListFragment(), OVERVIEW_TAG);
                            break;
                        case 1:
                            transaction.add(R.id.flContent, new OverviewCardsFragment(), OVERVIEW_TAG);
                            break;
                        case 2:
                            transaction.add(R.id.flContent, new OverviewStaggeredGridFragment(), OVERVIEW_TAG);
                        }
                        transaction.commit();
                    }
                }).show();
        break;
    case R.id.action_earliest_unread:
        if (prefHelper.hideRead()) {
            int n = comics.size() - 1;
            if (n > 0)
                showComic(n);
        } else {
            RealmComic comic = comics.where().equalTo("isRead", false)
                    .findAllSorted("comicNumber", Sort.ASCENDING).first();
            if (comic != null)
                goToComic(comic.getComicNumber() - 1);
        }
    }
    return super.onOptionsItemSelected(item);
}

From source file:co.vmob.sample.FragmentTabHost.java

public void addTab(TabHost.TabSpec tabSpec, Class<?> clss, Bundle args) {
    tabSpec.setContent(new DummyTabFactory(mContext));
    final String tag = tabSpec.getTag();

    final TabInfo info = new TabInfo(tag, clss, args);

    if (mAttached) {
        // If we are already attached to the window, then check to make
        // sure this tab's fragment is inactive if it exists.  This shouldn't
        // normally happen.
        info.fragment = mFragmentManager.findFragmentByTag(tag);
        if (info.fragment != null && !info.fragment.isDetached()) {
            final FragmentTransaction ft = mFragmentManager.beginTransaction();
            ft.detach(info.fragment);
            ft.commit();//from w w  w  . j  a va  2 s  .co  m
        }
    }

    mTabs.add(info);
    addTab(tabSpec);
}

From source file:com.dream.freightapp.app.ui.tool.TabManager.java

@Override
public void onTabChanged(String tabId) {
    TabInfo newTabInfo = tabs.get(tabId);
    if (lastTabInfo != newTabInfo) {
        FragmentTransaction fragmentTransaction = fragmentActivity.getSupportFragmentManager()
                .beginTransaction();/*from   w w w .ja v a  2 s .co  m*/
        if (lastTabInfo != null) {
            if (lastTabInfo.fragment != null) {
                fragmentTransaction.detach(lastTabInfo.fragment);
            }
        }
        if (newTabInfo != null) {
            if (newTabInfo.fragment == null) {
                newTabInfo.fragment = Fragment.instantiate(fragmentActivity, newTabInfo.clss.getName(),
                        newTabInfo.bundle);
                fragmentTransaction.add(containerId, newTabInfo.fragment, newTabInfo.tag);
            } else {
                fragmentTransaction.attach(newTabInfo.fragment);
            }
        }

        lastTabInfo = newTabInfo;
        fragmentTransaction.commit();
        fragmentActivity.getSupportFragmentManager().executePendingTransactions();
    }
}

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

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

    View view = inflater.inflate(R.layout.dialog_send_pk, container);

    Intent i = getActivity().getIntent();
    Bundle b = i.getExtras();// www. j  av a 2s .  c  o  m
    safe_lid = b.getString(Safe.P_SAFE_LID);

    peer = D_Peer.getPeerByLID(safe_lid, true, false);
    if (peer == null) {
        Toast.makeText(getActivity(), "No peer. Reload!", Toast.LENGTH_SHORT).show();
        //finish();
    }

    exportByPhoto = (Button) view.findViewById(R.id.dialog_send_pk_export_by_picture);
    sendVia = (Button) view.findViewById(R.id.dialog_send_pk_send_via);

    getDialog().setTitle("Export public key");

    exportByPhoto.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            if (Build.VERSION.SDK_INT < 19) {
                Intent intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(intent, SELECT_PHOTO);

                FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
                ft.detach(SendPK.this);
                ft.commit();
            } else {
                Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
                intent.setType("image/*");
                startActivityForResult(intent, SELECT_PHOTO_KITKAT);
                FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
                ft.detach(SendPK.this);
                ft.commit();
            }
        }
    });

    sendVia.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (peer == null) {
                Toast.makeText(getActivity(), "No peer. Reload!", Toast.LENGTH_SHORT).show();
                return;
                //finish();
            }
            //DD_Address adr = new DD_Address(peer);

            String msgBody = DD.getExportTextObjectBody(peer); //adr.getBytes());

            Intent i = new Intent(Intent.ACTION_SEND);
            i.setType("text/plain");
            i.putExtra(Intent.EXTRA_TEXT, msgBody); //Safe.SAFE_TEXT_MY_BODY_SEP + Util.stringSignatureFromByte(adr.getBytes()));
            /*
                        String slogan = peer.getSlogan_MyOrDefault();
                        if (slogan == null) slogan = "";
                        else slogan = "\""+slogan+"\"";
                        i.putExtra(Intent.EXTRA_SUBJECT, "DDP2P: Safe Address of \""+peer.getName()+"\",  "+slogan+Safe.SAFE_TEXT_MY_HEADER_SEP);
            */
            i.putExtra(Intent.EXTRA_SUBJECT, DD.getExportTextObjectTitle(peer));
            i = Intent.createChooser(i, "send Public key");
            startActivity(i);
            FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
            ft.detach(SendPK.this);
            ft.commit();
        }
    });

    return view;
}

From source file:com.umeng.comm.ui.activities.BaseFragmentActivity.java

/**
 * @param fragment//www.j  a va2 s . c om
 */
public void detach(Fragment fragment) {
    if (null != fragment) {
        FragmentTransaction transaction = mFragmentManager.beginTransaction();
        transaction.detach(fragment);
        transaction.commit();
    }
}

From source file:com.google.android.apps.mytracks.TabManager.java

public void addTab(TabSpec tabSpec, Class<?> clss, Bundle bundle) {
    tabSpec.setContent(new DummyTabContentFactory(fragmentActivity));

    String tag = tabSpec.getTag();
    TabInfo tabInfo = new TabInfo(tag, clss, bundle);

    /*/*from w  w w . j av  a 2  s  .co m*/
     * Check to see if we already have a fragment for this tab, probably from a
     * previously saved state. If so, deactivate it, because our initial state
     * is that a tab isn't shown.
     */
    tabInfo.fragment = fragmentActivity.getSupportFragmentManager().findFragmentByTag(tag);
    if (tabInfo.fragment != null && !tabInfo.fragment.isDetached()) {
        FragmentTransaction fragmentTransaction = fragmentActivity.getSupportFragmentManager()
                .beginTransaction();
        fragmentTransaction.detach(tabInfo.fragment);
        fragmentTransaction.commit();
    }
    tabs.put(tag, tabInfo);
    tabHost.addTab(tabSpec);
}

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

private void recreateFragmentView(final Fragment fragment) {
    FragmentTransaction fragTransaction = getSupportFragmentManager().beginTransaction();
    fragTransaction.detach(fragment);
    fragTransaction.attach(fragment);// w w w  .jav  a  2  s . com
    fragTransaction.commitAllowingStateLoss();
    if (fragment instanceof CustomFragmentDialog) {
        mCustomFragmentDialog = (CustomFragmentDialog) fragment;
    }
}

From source file:org.cowboycoders.cyclisimo.TabManager.java

@Override
public void onTabChanged(String tabId) {
    TabInfo newTabInfo = tabs.get(tabId);
    if (lastTabInfo != newTabInfo) {
        FragmentTransaction fragmentTransaction = fragmentActivity.getSupportFragmentManager()
                .beginTransaction();//from  ww  w .jav  a 2 s . c om
        if (lastTabInfo != null) {
            if (lastTabInfo.fragment != null) {
                fragmentTransaction.detach(lastTabInfo.fragment);
            }
        }
        if (newTabInfo != null) {
            if (newTabInfo.fragment == null) {
                newTabInfo.fragment = Fragment.instantiate(fragmentActivity, newTabInfo.clss.getName(),
                        newTabInfo.bundle);
                fragmentTransaction.add(containerId, newTabInfo.fragment, newTabInfo.tag);
            } else {
                fragmentTransaction.attach(newTabInfo.fragment);
            }
        }

        lastTabInfo = newTabInfo;
        fragmentTransaction.commitAllowingStateLoss();
        fragmentActivity.getSupportFragmentManager().executePendingTransactions();
    }
}

From source file:com.glabs.homegenie.fragments.GroupsViewFragment.java

private void _setCurrentGroup(int pindex) {
    final Fragment f = mAdapter.getItem(mCurrentGroup);
    if (f != null) {
        new Handler().post(new Runnable() {
            @Override/* ww  w .ja v a  2 s . c  o  m*/
            public void run() {
                FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
                ft.detach(f);
                ft.attach(f);
                ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
                ft.commit();
            }
        });
    }
    mCurrentGroup = pindex;
    UpdateCurrentGroupModules();
    UpdateCurrentGroupMenu();
}

From source file:com.ai.eve.lenovo.widget.FragmentTabHost.java

public void addTab(TabSpec tabSpec, Class<?> clss, Bundle args) {
    tabSpec.setContent(new DummyTabFactory(mContext));
    String tag = tabSpec.getTag();

    TabInfo info = new TabInfo(tag, clss, args);

    if (mAttached) {
        // If we are already attached to the window, then check to make
        // sure this tab's fragment is inactive if it exists.  This shouldn't
        // normally happen.
        info.fragment = mFragmentManager.findFragmentByTag(tag);
        if (info.fragment != null && !info.fragment.isDetached()) {
            FragmentTransaction ft = mFragmentManager.beginTransaction();
            ft.detach(info.fragment);
            ft.commitAllowingStateLoss();
        }//from   w w w.  ja  v a2 s.c om
    }

    mTabs.add(info);
    addTab(tabSpec);
}