Example usage for android.app FragmentTransaction remove

List of usage examples for android.app FragmentTransaction remove

Introduction

In this page you can find the example usage for android.app FragmentTransaction remove.

Prototype

public abstract FragmentTransaction remove(Fragment fragment);

Source Link

Document

Remove an existing fragment.

Usage

From source file:biz.wiz.android.wallet.ui.AddressBookActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.address_book_content);

    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    final FragmentManager fragmentManager = getFragmentManager();

    walletAddressesFragment = (WalletAddressesFragment) fragmentManager.findFragmentByTag(TAG_LEFT);
    sendingAddressesFragment = (SendingAddressesFragment) fragmentManager.findFragmentByTag(TAG_RIGHT);

    final FragmentTransaction removal = fragmentManager.beginTransaction();

    if (walletAddressesFragment == null)
        walletAddressesFragment = new WalletAddressesFragment();
    else//from  w  w w.  j  a va2s .  c om
        removal.remove(walletAddressesFragment);

    if (sendingAddressesFragment == null)
        sendingAddressesFragment = new SendingAddressesFragment();
    else
        removal.remove(sendingAddressesFragment);

    if (!removal.isEmpty()) {
        removal.commit();
        fragmentManager.executePendingTransactions();
    }

    final ViewPager pager = (ViewPager) findViewById(R.id.address_book_pager);
    if (pager != null) {
        pager.setAdapter(
                new TwoFragmentAdapter(fragmentManager, walletAddressesFragment, sendingAddressesFragment));

        final ViewPagerTabs pagerTabs = (ViewPagerTabs) findViewById(R.id.address_book_pager_tabs);
        pagerTabs.addTabLabels(R.string.address_book_list_receiving_title,
                R.string.address_book_list_sending_title);

        pager.setOnPageChangeListener(pagerTabs);
        final int position = 1;
        pager.setCurrentItem(position);
        pager.setPageMargin(2);
        pager.setPageMarginDrawable(R.color.bg_less_bright);

        pagerTabs.onPageSelected(position);
        pagerTabs.onPageScrolled(position, 0, 0);
    } else {
        fragmentManager.beginTransaction()
                .add(R.id.wallet_addresses_fragment, walletAddressesFragment, TAG_LEFT)
                .add(R.id.sending_addresses_fragment, sendingAddressesFragment, TAG_RIGHT).commit();
    }

    updateFragments();
}

From source file:com.matthewmitchell.peercoin_android_wallet.ui.AddressBookActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.address_book_content);

    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    final FragmentManager fragmentManager = getFragmentManager();

    walletAddressesFragment = (WalletAddressesFragment) fragmentManager.findFragmentByTag(TAG_LEFT);
    sendingAddressesFragment = (SendingAddressesFragment) fragmentManager.findFragmentByTag(TAG_RIGHT);

    final FragmentTransaction removal = fragmentManager.beginTransaction();

    if (walletAddressesFragment == null)
        walletAddressesFragment = new WalletAddressesFragment();
    else//from   w ww .ja v  a2s .  co  m
        removal.remove(walletAddressesFragment);

    if (sendingAddressesFragment == null)
        sendingAddressesFragment = new SendingAddressesFragment();
    else
        removal.remove(sendingAddressesFragment);

    if (!removal.isEmpty()) {
        removal.commit();
        fragmentManager.executePendingTransactions();
    }

    final ViewPager pager = (ViewPager) findViewById(R.id.address_book_pager);
    if (pager != null) {
        pager.setAdapter(
                new TwoFragmentAdapter(fragmentManager, walletAddressesFragment, sendingAddressesFragment));

        final ViewPagerTabs pagerTabs = (ViewPagerTabs) findViewById(R.id.address_book_pager_tabs);
        pagerTabs.addTabLabels(R.string.address_book_list_receiving_title,
                R.string.address_book_list_sending_title);

        pager.setOnPageChangeListener(pagerTabs);
        final int position = 1;
        pager.setCurrentItem(position);
        pager.setPageMargin(2);
        pager.setPageMarginDrawable(R.color.bg_less_bright);

        pagerTabs.onPageSelected(position);
        pagerTabs.onPageScrolled(position, 0, 0);
    } else {
        fragmentManager.beginTransaction()
                .add(R.id.wallet_addresses_fragment, walletAddressesFragment, TAG_LEFT)
                .add(R.id.sending_addresses_fragment, sendingAddressesFragment, TAG_RIGHT).commit();
    }

    runAfterLoad(new Runnable() {

        @Override
        public void run() {
            updateFragments();
        }

    });

}

From source file:com.spacejake.jake.ultimatepurduediner.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mTitle = getTitle();//from   w ww . j a v  a  2  s.  c  o m
    mNavigationDrawerFragment = (NavigationDrawerFragment) getFragmentManager()
            .findFragmentById(R.id.navigation_drawer);

    // Set up the drawer.
    mNavigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout));

    cal = Calendar.getInstance();
    dateString = format.format(cal.getTime());

    spinner = (Spinner) findViewById(R.id.spinner);
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            updateMeal();
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });

    listView = (ListView) findViewById(R.id.listview);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            String foodName = adapterView.getItemAtPosition(i).toString();
            String meal = spinner.getSelectedItem().toString();

            FragmentTransaction ft = getFragmentManager().beginTransaction();
            Fragment previous = getFragmentManager().findFragmentByTag("floatingFood");

            if (previous != null) {
                ft.remove(previous);
            }

            ft.addToBackStack(null);

            DialogFragment frag = FloatingFood.newInstance(foodName, mTitle.toString(), meal, cal);
            frag.show(ft, "floatingFood");
        }
    });

}

From source file:cmput301.f13t01.readstory.ReadFragmentActivity.java

/**
 * displays screen specific help/* w  w w . ja v a  2 s  .c  om*/
 */
private void onSelectHelp() {
    android.app.FragmentTransaction ft = getFragmentManager().beginTransaction();
    android.app.Fragment prev = getFragmentManager().findFragmentByTag("help_dialog");
    if (prev != null) {
        ft.remove(prev);
    }
    ft.addToBackStack(null);
    android.app.DialogFragment newFragment = (android.app.DialogFragment) HelpFragment
            .newInstance(HelpMessage.READ_STORY);
    newFragment.show(ft, "help_dialog");
}

From source file:cmput301.f13t01.editstory.EditStoryActivity.java

private void onSelectHelp() {
    android.app.FragmentTransaction ft = getFragmentManager().beginTransaction();
    android.app.Fragment prev = getFragmentManager().findFragmentByTag("help_dialog");
    if (prev != null) {
        ft.remove(prev);
    }//from   w w w .j  a v a  2s. c o  m
    ft.addToBackStack(null);

    android.app.DialogFragment newFragment = (android.app.DialogFragment) HelpFragment
            .newInstance(HelpMessage.EDIT_STORY);
    newFragment.show(ft, "help_dialog");
}

From source file:cmput301.f13t01.editstory.EditStoryActivity.java

/**
 * Display selection of fragment/*from  ww w .java 2 s .  c o m*/
 */
public void showFragmentSelection() {
    android.app.FragmentTransaction ft = getFragmentManager().beginTransaction();
    android.app.Fragment prev = getFragmentManager().findFragmentByTag("choice_dialog");
    if (prev != null) {
        ft.remove(prev);
    }
    ft.addToBackStack(null);

    android.app.DialogFragment newFragment = (android.app.DialogFragment) StoryFragmentListFragment
            .newInstance();
    newFragment.show(ft, "choice_dialog");
}

From source file:com.android.mail.browse.AttachmentActionHandler.java

/**
 * Displays a loading dialog to be used for downloading attachments.
 * Must be called on the UI thread./* ww  w.j a  v  a2  s .  c om*/
 */
public void showDownloadingDialog() {
    final FragmentTransaction ft = mFragmentManager.beginTransaction();
    final Fragment prev = mFragmentManager.findFragmentByTag(PROGRESS_FRAGMENT_TAG);
    if (prev != null) {
        ft.remove(prev);
    }
    ft.addToBackStack(null);

    // Create and show the dialog.
    final DialogFragment newFragment = AttachmentProgressDialogFragment.newInstance(mAttachment);
    newFragment.show(ft, PROGRESS_FRAGMENT_TAG);
}

From source file:it.gmariotti.cardslib.demo.extras.MainActivity.java

private void openDialogFragment(DialogFragment dialogStandardFragment) {
    if (dialogStandardFragment != null) {
        FragmentManager fm = getFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        Fragment prev = fm.findFragmentByTag("carddemo_dialog_extras");
        if (prev != null) {
            ft.remove(prev);
        }/*from   ww  w . j a va  2  s . c  o  m*/
        //ft.addToBackStack(null);

        dialogStandardFragment.show(ft, "carddemo_dialog_extras");
    }
}

From source file:com.vaporwarecorp.mirror.feature.main.MirrorActivity.java

private void hideFragment(final Fragment fragment, final boolean removeParentView,
        final boolean addedToBackStack, final String tag) {
    final FragmentManager manager = getFragmentManager();
    if (manager.findFragmentByTag(tag) != null) {
        final FragmentTransaction transaction = manager.beginTransaction();
        transaction.remove(fragment);
        transaction.commit();/*  w w w. j a v  a2  s.  c  o  m*/
        if (addedToBackStack) {
            manager.popBackStack();
        }

        final int viewId = getParentId(fragment);
        if (removeParentView && viewId != 0) {
            mContentContainer.removeBorderView(viewId);
        }
    }
}

From source file:com.ysy.classpower_utils.search_view.OwnSearchViewLayout.java

private void hideContentFragment() {
    if (mFragmentManager == null) {
        Log.e(LOG_TAG, "Fragment Manager is null. Returning");
        return;//from ww w.  ja va2s .  co  m
    }
    final FragmentTransaction transaction = mFragmentManager.beginTransaction();
    transaction.remove(mExpandedContentFragment).commit();
}