Example usage for android.app FragmentManager findFragmentByTag

List of usage examples for android.app FragmentManager findFragmentByTag

Introduction

In this page you can find the example usage for android.app FragmentManager findFragmentByTag.

Prototype

public abstract Fragment findFragmentByTag(String tag);

Source Link

Document

Finds a fragment that was identified by the given tag either when inflated from XML or as supplied when added in a transaction.

Usage

From source file:mx.openpay.android.example.AddCardActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.activity_add_card);

    this.progressFragment = ProgressDialogFragment.newInstance(R.string.progress_message);

    FragmentManager fm = this.getFragmentManager();
    this.deviceIdFragment = (DeviceIdFragment) fm.findFragmentByTag("DeviceCollector");
    // If not retained (or first time running), we need to create it.
    if (this.deviceIdFragment == null) {
        this.deviceIdFragment = new DeviceIdFragment();
        fm.beginTransaction().add(this.deviceIdFragment, "DeviceCollector").commit();
    }/* w  ww  .j a  v a  2 s . c  o m*/
    final RadioButton radio1 = (RadioButton) this.findViewById(R.id.radioButton1);
    radio1.setChecked(true);

}

From source file:systems.soapbox.ombuds.client.ui.AddressBookActivity.java

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

    setContentView(R.layout.address_book_content);
    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    super.setAnimateOnPause(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 .java  2s  .c o  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();
    }

    updateFragments();
}

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//ww  w.  j  a  va  2  s  . 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();
    }

    updateFragments();
}

From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.FetchReservationsToDate.java

/**
 * Clears adapter of current data and fills it with fetched reservations.
 * In process it clears details fragment, so it could not display information about no longer existing reservation.
 *
 * @param resultList fetched reservations
 *///w ww.j  a  va  2 s  .  c o  m
@Override
protected void onPostExecute(List<Reservation> resultList) {
    reservationAdapter.clear();
    if (resultList != null && !resultList.isEmpty()) {
        for (Reservation reservation : resultList) {
            try {
                reservationAdapter.add(reservation);
            } catch (Exception e) {
                setState(ERROR, e);
                Log.e(TAG, e.getLocalizedMessage(), e);
            }
        }
    }

    FragmentManager fm = activity.getFragmentManager();

    ReservationDetailsFragment details = new ReservationDetailsFragment();
    ReservationDetailsFragment frag = (ReservationDetailsFragment) fm
            .findFragmentByTag(ReservationDetailsFragment.TAG);
    if (frag != null) {
        FragmentTransaction ft = fm.beginTransaction();
        ft.replace(R.id.details, details, ReservationDetailsFragment.TAG);
        ft.commit();
    }
}

From source file:org.openlmis.core.view.activity.BaseActivity.java

private void initDataFragment() {
    FragmentManager fm = getFragmentManager();
    dataFragment = (RetainedFragment) fm.findFragmentByTag("RetainedFragment");

    if (dataFragment == null) {
        dataFragment = new RetainedFragment();
        fm.beginTransaction().add(dataFragment, "RetainedFragment").commit();
    }/*w  w w .  ja  va 2s  .c o m*/
}

From source file:com.learnit.LearnIt.activities.MainActivity.java

public void onArticleSelected(int position) {
    // Create a new listOfFragments
    MySmartFragment fragment;/*from   w w  w  . j  a v  a 2 s.co  m*/
    switch (position) {
    case ADD_WORDS_FRAGMENT:
        fragment = new AddWordFragment();
        fragment.identifier = ADD_WORDS_FRAGMENT;
        Log.d(LOG_TAG, "Created AddWordFragment with tag " + fragment.identifier);
        break;
    case DICTIONARY_FRAGMENT:
        fragment = new DictFragment();
        fragment.identifier = DICTIONARY_FRAGMENT;
        Log.d(LOG_TAG, "Created Dictionary Fragment with tag " + fragment.identifier);
        break;
    case LEARN_WORDS_FRAGMENT:
        fragment = new LearnCasualFragment();
        fragment.identifier = LEARN_WORDS_FRAGMENT;
        Log.d(LOG_TAG, "Created LearnFragment with tag " + fragment.identifier);
        break;
    default:
        fragment = null;
    }
    // Update the layout
    FragmentManager fm = getFragmentManager();

    if (fm.findFragmentByTag("android:switcher:" + 0 + ":" + position) == null) {
        FragmentTransaction ft = fm.beginTransaction();
        ft.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
        ft.replace(R.id.view_group_id, fragment, "android:switcher:" + 0 + ":" + position);
        Log.d(LOG_TAG, "current fragment id = " + fragment.getId() + " and tag = " + fragment.getTag()
                + ((Object) fragment).getClass().getName());
        ft.commit();
    }
    _currentItemShown = position;
    Log.d(LOG_TAG, "onArticleSelected current item set to " + _currentItemShown);
}

From source file:com.google.samples.apps.iosched.map.MapActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FragmentManager fm = getFragmentManager();
    mMapFragment = (MapFragment) fm.findFragmentByTag("map");

    mDetachedMode = getIntent().getBooleanExtra(EXTRA_DETACHED_MODE, false);

    if (isFinishing()) {
        return;/* www .jav a2  s . c o  m*/
    }

    setContentView(R.layout.map_act);
    mInfoContainer = findViewById(R.id.map_detail_popup);

    // ANALYTICS SCREEN: View the Map screen on a phone
    // Contains: Nothing (Page name is a constant)
    AnalyticsHelper.sendScreenView(SCREEN_LABEL);

    overridePendingTransition(0, 0);
}

From source file:android.support.v17.leanback.app.GuidedStepFragment.java

/**
 * Returns the current GuidedStepFragment on the fragment transaction stack.
 * @return The current GuidedStepFragment, if any, on the fragment transaction stack.
 *///from   w w  w  . java  2 s.c  om
public static GuidedStepFragment getCurrentGuidedStepFragment(FragmentManager fm) {
    Fragment f = fm.findFragmentByTag(TAG_LEAN_BACK_ACTIONS_FRAGMENT);
    if (f instanceof GuidedStepFragment) {
        return (GuidedStepFragment) f;
    }
    return null;
}

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  w w.jav a  2 s.c o 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.example.android.cloudnotes.ui.HomeActivity.java

/**
 * Callback from child fragment//w  w w . j  a v a  2s .  c  o  m
 */
public void onNoteDeleted() {
    // remove the NoteEditFragment after a deletion
    FragmentManager fm = getFragmentManager();
    NoteEditFragment edit = (NoteEditFragment) fm.findFragmentByTag(NOTE_EDIT_TAG);
    if (edit != null) {
        FragmentTransaction ft = fm.beginTransaction();
        ft.remove(edit);
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        ft.commit();
    }
}