Example usage for android.support.v4.app FragmentManager findFragmentById

List of usage examples for android.support.v4.app FragmentManager findFragmentById

Introduction

In this page you can find the example usage for android.support.v4.app FragmentManager findFragmentById.

Prototype

public abstract Fragment findFragmentById(int id);

Source Link

Document

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

Usage

From source file:com.deliciousdroid.activity.BrowseBookmarks.java

public void saveHandler(View v) {
    FragmentManager fm = getSupportFragmentManager();
    AddBookmarkFragment addFrag = (AddBookmarkFragment) fm.findFragmentById(R.id.addcontent);

    if (addFrag != null) {
        addFrag.saveHandler(v);/*from ww w .j a  va  2  s  . c  om*/
    }
}

From source file:com.deliciousdroid.activity.BrowseBookmarks.java

public void cancelHandler(View v) {
    FragmentManager fm = getSupportFragmentManager();
    AddBookmarkFragment addFrag = (AddBookmarkFragment) fm.findFragmentById(R.id.addcontent);

    if (addFrag != null) {
        addFrag.cancelHandler(v);/*from www. ja v a 2  s  . c om*/
    }
}

From source file:com.money.manager.ex.RepeatingTransactionListActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // check if launch from notification
    if (getIntent() != null && getIntent().getBooleanExtra(INTENT_EXTRA_LAUNCH_NOTIFICATION, false)) {
        Passcode passcode = new Passcode(this);
        if (passcode.hasPasscode()) {
            Intent intent = new Intent(this, PasscodeActivity.class);
            // set action and data
            intent.setAction(PasscodeActivity.INTENT_REQUEST_PASSWORD);
            intent.putExtra(PasscodeActivity.INTENT_MESSAGE_TEXT, getString(R.string.enter_your_passcode));
            // start activity
            startActivityForResult(intent, INTENT_REQUEST_PASSCODE);
        }// w ww  .  j  a  v  a  2s.c o m
    }
    // set actionbar
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    // set fragment and fragment manager
    FragmentManager fm = getSupportFragmentManager();
    listFragment = new RepeatingTransactionListFragment();
    // attach fragment on activity
    if (fm.findFragmentById(android.R.id.content) == null) {
        fm.beginTransaction().add(android.R.id.content, listFragment, FRAGMENTTAG).commit();
    }
}

From source file:click.kobaken.rxirohaandroid_sample.view.activity.MainActivity.java

private void switchFragment(@NonNull Fragment fragment, String tag) {
    if (fragment.isAdded()) {
        return;/*from   w w  w. jav  a  2s  .co m*/
    }

    final FragmentManager manager = getSupportFragmentManager();
    final FragmentTransaction fragmentTransaction = manager.beginTransaction();

    final Fragment currentFragment = manager.findFragmentById(R.id.container);
    if (currentFragment != null) {
        fragmentTransaction.detach(currentFragment);
    }

    if (fragment.isDetached()) {
        fragmentTransaction.attach(fragment);
    } else {
        fragmentTransaction.add(R.id.container, fragment, tag);
    }
    fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE).commit();
}

From source file:com.yairkukielka.feedhungry.EntryListFragment.java

private void removeLoadingFragment() {
    if (getActivity() != null) {
        FragmentManager fragmentManager = getSherlockActivity().getSupportFragmentManager();
        if (loadingFragment != null && fragmentManager.findFragmentById(loadingFragment.getId()) != null) {
            fragmentManager.beginTransaction().remove(loadingFragment).commitAllowingStateLoss();
        }//from  w  ww  . j  a  v  a  2  s.  co m
    }

}

From source file:com.gruporaido.tasker_library.util.Helper.java

/**
 * Remove the specified fragment with an animation.
 * <b><i>Note: Transaction done with possible state loss</i></b>
 *
 * @param fragmentManager//  w w w  .ja va 2  s .c  o m
 * @param resourceId
 * @param inAnimation
 * @param outAnimation
 */
public void removeFragment(FragmentManager fragmentManager, int resourceId, int inAnimation, int outAnimation) {
    Fragment fragment = fragmentManager.findFragmentById(resourceId);
    if (fragment != null) {
        android.support.v4.app.FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.setCustomAnimations(inAnimation, outAnimation).remove(fragment).commitAllowingStateLoss();

    }
}

From source file:com.dwdesign.tweetings.activity.LinkHandlerActivity.java

@Override
public void onStart() {
    if (isDualPaneMode() && mFragment != null) {
        final FragmentManager fm = getSupportFragmentManager();
        final Fragment f = fm.findFragmentById(R.id.content);
        if (f != null) {
            final FragmentTransaction ft = fm.beginTransaction();
            ft.remove(f);/* www  .  j  a v a2  s .  c  om*/
            ft.commit();
        }
    }
    super.onStart();
}

From source file:com.fusionx.lightirc.ui.IRCActivity.java

@Override
public void onCreate(final Bundle savedInstanceState) {
    setTheme(UIUtils.getThemeInt());/*w  w w .  j  av  a  2 s  .  co  m*/

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

    final ServerConfiguration.Builder builder = getIntent().getParcelableExtra("server");
    mServerTitle = builder != null ? builder.getTitle() : getIntent().getStringExtra("serverTitle");

    final FragmentManager fm = getSupportFragmentManager();

    setUpSlidingMenu(fm);

    mIRCPagerFragment = (IRCPagerFragment) fm.findFragmentById(R.id.pager_fragment);
    mServiceFragment = (ServiceFragment) fm.findFragmentByTag("service");

    final boolean isFirstStart = mServiceFragment == null;
    final ActionBar actionBar = getSupportActionBar();
    if (isFirstStart) {
        mServiceFragment = new ServiceFragment();
        fm.beginTransaction().add(mServiceFragment, "service").commit();
        actionBar.setSubtitle(getString(R.string.status_connecting));
    } else if (getServer() != null) {
        final ServerEventBus bus = getServer().getServerEventBus();
        bus.register(mEventReceiver);
        // TODO - this is misnamed - rename it
        mIRCPagerFragment.onCreateServerFragment(mServerTitle);
        actionBar.setSubtitle(MiscUtils.getStatusString(this, getServer().getStatus()));
    }
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setTitle(mServerTitle);

    final PagerSlidingTabStrip tabs = (PagerSlidingTabStrip) findViewById(R.id.pager_tabs);
    tabs.setOnPageChangeListener(mListener);
    tabs.setTextColorResource(android.R.color.white);
}

From source file:com.conferenceengineer.android.iosched.ui.tablet.SessionsSandboxMultiPaneActivity.java

private void showFullUI(boolean fullUI) {
    mFullUI = fullUI;//www .  ja  va2s. c  o  m
    final FragmentManager fm = getSupportFragmentManager();

    if (fullUI) {
        onNavigationItemSelected(0, 0);
        fm.beginTransaction().show(fm.findFragmentById(R.id.fragment_tracks_dropdown)).commit();
    } else {
        fm.beginTransaction().hide(fm.findFragmentById(R.id.fragment_tracks_dropdown)).commit();
    }
}

From source file:com.sith.login.FBLoginActivity.java

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

    getActionBar().setDisplayHomeAsUpEnabled(true);

    // redirectState=getIntent().getExtras().getString("riderect_state");
    isConnect = getIntent().getExtras().getBoolean("isConnect");

    uiHelper = new UiLifecycleHelper(this, callback);
    uiHelper.onCreate(savedInstanceState);

    if (savedInstanceState != null) {
        String name = savedInstanceState.getString(PENDING_ACTION_BUNDLE_KEY);
        pendingAction = PendingAction.valueOf(name);
    }/* w  w  w  . j  ava  2s. c  om*/

    setContentView(R.layout.login);

    FragmentManager fm1 = getSupportFragmentManager();
    fragments[LOGINMETHOD] = fm1.findFragmentById(R.id.loginMethodFragment);
    fragments[PROFILE] = fm1.findFragmentById(R.id.profileFragment);

    FragmentTransaction transaction = fm1.beginTransaction();
    for (int i = 0; i < fragments.length; i++) {
        transaction.hide(fragments[i]);
    }
    transaction.commit();

    loginButton = (LoginButton) findViewById(R.id.login_button);
    List<String> additionalPermissions = new ArrayList<String>();
    additionalPermissions.add("publish_stream");
    additionalPermissions.add("publish_actions");
    loginButton.setPublishPermissions(additionalPermissions);
    loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
        // @Override
        public void onUserInfoFetched(GraphUser user) {
            FBLoginActivity.this.user = user;
            updateUserInfo();
            // It's possible that we were waiting for this.user to
            // be populated in order to post a
            // status update.
            handlePendingAction();
        }
    });

    profilePictureViewFB = (ProfilePictureView) findViewById(R.id.profilePictureFB);
    greeting = (TextView) findViewById(R.id.greeting);

    controlsContainer = (ViewGroup) findViewById(R.id.main_ui_container);

    final FragmentManager fm = getSupportFragmentManager();
    Fragment fragment = fm.findFragmentById(R.id.fragment_container);
    if (fragment != null) {
        // If we're being re-created and have a fragment, we need to a) hide
        // the main UI controls and
        // b) hook up its listeners again.
        controlsContainer.setVisibility(View.GONE);

    }

    // Listen for changes in the back stack so we know if a fragment got
    // popped off because the user
    // clicked the back button.
    fm.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {
        // @Override
        public void onBackStackChanged() {
            if (fm.getBackStackEntryCount() == 0) {
                // We need to re-show our UI.
                controlsContainer.setVisibility(View.VISIBLE);
            }
        }
    });

    // Fonts
    Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Medium.ttf");
    greeting.setTypeface(tf);
}