Example usage for android.app Fragment getId

List of usage examples for android.app Fragment getId

Introduction

In this page you can find the example usage for android.app Fragment getId.

Prototype

final public int getId() 

Source Link

Document

Return the identifier this fragment is known by.

Usage

From source file:it.mobistego.MainActivity.java

@Override
public void onMainFragmentGridItemSelected(MobiStegoItem mobiStegoItem) {
    if (mobiStegoItem != null) {
        ItemViewFragment viewFragment = new ItemViewFragment();
        Bundle args = new Bundle();
        viewFragment.setArguments(args);
        viewFragment.setMobiStegoItem(mobiStegoItem);
        FragmentTransaction transaction = getFragmentManager().beginTransaction();

        Fragment mainFrag = getFragmentManager().findFragmentByTag(Constants.CONTAINER);

        transaction.replace(mainFrag.getId(), viewFragment);
        transaction.addToBackStack(null);
        transaction.commit();/*from   w  w w  .j a v  a 2 s. co  m*/
    }
}

From source file:net.sf.sprockets.app.ui.PanesActivity.java

/**
 * Use your own layout for the panes./*from www .  j a  v  a  2  s . c o  m*/
 *
 * @param pagerId {@code R.id} value for the ViewPager in the single pane layout
 * @param pane1Id {@code R.id} value for the first pane in the multi-pane layout
 * @param pane2Id {@code R.id} value for the second pane in the multi-pane layout
 */
public void setContentView(int layoutResId, int pagerId, int pane1Id, int pane2Id) {
    setContentView(layoutResId);
    Fragment pane1 = findFragmentByPane(1);
    Fragment pane2 = findFragmentByPane(2);
    ViewPager pager = findById(this, pagerId);
    /* do we need to move the fragments between the single and multi-pane layouts? */
    FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = null;
    if (pane2 == null) {
        pane2 = getFragment(2);
    } else if (pane2.getId() != (pager != null ? pagerId : pane2Id)) {
        ft = fm.beginTransaction().remove(pane2); // remove in reverse to preserve indices
    }
    if (pane1 == null) {
        pane1 = getFragment(1);
    } else if (pane1.getId() != (pager != null ? pagerId : pane1Id)) {
        if (ft == null) {
            ft = fm.beginTransaction();
        }
        ft.remove(pane1);
    }
    if (ft != null) {
        ft.commitAllowingStateLoss();
        fm.executePendingTransactions(); // force removes so can add to a different container
    }
    /* add the fragments to the panes */
    if (pager != null) {
        pager.setAdapter(new PanesAdapter(pane1, pane2));
    } else {
        ft = null;
        if (pane1.getId() != pane1Id) {
            ft = Fragments.open(this).add(pane1Id, pane1, PANE_1);
        }
        if (pane2.getId() != pane2Id) {
            if (ft == null) {
                ft = Fragments.open(this);
            }
            ft.add(pane2Id, pane2, PANE_2);
        }
        if (ft != null) {
            ft.commitAllowingStateLoss();
        }
    }
}

From source file:com.frostwire.android.gui.activities.MainActivity2.java

private void switchContent(Fragment fragment, boolean addToStack) {
    //        hideFragments(getFragmentManager().beginTransaction()).show(fragment).commitAllowingStateLoss();
    if (addToStack && (fragmentsStack.isEmpty() || fragmentsStack.peek() != fragment.getId())) {
        fragmentsStack.push(fragment.getId());
    }/*from w w  w . j  av a2  s.c o m*/
    currentFragment = fragment;
    updateHeader(fragment);
}

From source file:com.bt.download.android.gui.activities.MainActivity.java

private void switchContent(Fragment fragment, boolean addToStack) {
    hideFragments(getFragmentManager().beginTransaction()).show(fragment).commitAllowingStateLoss();
    if (addToStack && (fragmentsStack.isEmpty() || fragmentsStack.peek() != fragment.getId())) {
        fragmentsStack.push(fragment.getId());
    }//from   www .j  av a 2  s  . c o m

    if (fragment instanceof TransfersFragment) {
        if (transfers.adBanner != null) {
            transfers.adBanner.startAutoScroll();
        }
    } else {
        if (transfers.adBanner != null) {
            transfers.adBanner.stopAutoScroll();
        }
    }

    if (fragment instanceof SearchFragment) {
        if (search.adBanner != null) {
            search.adBanner.startAutoScroll();
        }
    } else {
        if (search.adBanner != null) {
            search.adBanner.stopAutoScroll();
        }
    }

    currentFragment = fragment;
    updateHeader(fragment);
}

From source file:org.dkf.jmule.activities.MainActivity.java

private void switchContent(Fragment fragment, boolean addToStack) {
    hideFragments(getFragmentManager().beginTransaction()).show(fragment).commitAllowingStateLoss();
    if (addToStack && (fragmentsStack.isEmpty() || fragmentsStack.peek() != fragment.getId())) {
        fragmentsStack.push(fragment.getId());
    }/*from  w  w w .  j  a va2 s  .c  o  m*/
    currentFragment = fragment;
    updateHeader(fragment);

    if (currentFragment instanceof MainFragment) {
        ((MainFragment) currentFragment).onShow();
    }
}

From source file:com.frostwire.android.gui.activities.MainActivity.java

private void switchContent(Fragment fragment, boolean addToStack) {
    hideFragments();//from ww  w  . ja  v a  2  s.  c  om
    FragmentTransaction transaction = getFragmentManager().beginTransaction().show(fragment);
    try {
        transaction.commitAllowingStateLoss();
    } catch (Throwable ignored) {
    }
    if (addToStack && (fragmentsStack.isEmpty() || fragmentsStack.peek() != fragment.getId())) {
        fragmentsStack.push(fragment.getId());
    }
    currentFragment = fragment;
    updateHeader(fragment);
    if (currentFragment instanceof MainFragment) {
        ((MainFragment) currentFragment).onShow();
    }
}