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.adstrosoftware.gpsplayground.MainActivity.java

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

    FragmentManager fragmentManager = getSupportFragmentManager();

    smallScreen = (fragmentManager.findFragmentById(R.id.featureListFragment) == null);

    if (smallScreen) {

        // Only add the fragment once to prevent overlapping fragments
        if (savedInstanceState == null) {
            Fragment fragment = FeatureListFragment.newInstance();

            fragmentManager.beginTransaction()
                    .add(R.id.fragmentContainer, fragment, fragment.getClass().getName()).commit();
        }/*from  w w  w . j  a va2  s .c  o  m*/
    }
}

From source file:com.java_lang_programming.android_recycleview_demo.ui.AutoScrollRecyclerViewActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_auto_scroll_recycler_view);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from   ww w. j a  va 2s  . c  o  m

    FragmentManager fragmentManager = getSupportFragmentManager();
    recyclerViewFragment = (AutoScrollRecyclerViewFragment) fragmentManager.findFragmentById(R.id.fragment);
}

From source file:com.money.manager.ex.account.AccountListActivity.java

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

    setContentView(R.layout.base_toolbar_activity);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    AccountListFragment listFragment = new AccountListFragment();
    Intent intent = getIntent();/* w  w w.  jav  a2 s.c  o m*/
    if (intent != null && !(TextUtils.isEmpty(intent.getAction()))) {
        listFragment.mAction = intent.getAction();
    }
    FragmentManager fm = getSupportFragmentManager();
    // attach fragment to activity
    if (fm.findFragmentById(R.id.content) == null) {
        fm.beginTransaction().add(R.id.content, listFragment, FRAGMENTTAG).commit();
    }

    Answers.getInstance().logCustom(new CustomEvent(AnswersEvents.AccountList.name()));
}

From source file:mobisocial.bento.ebento.ui.PeopleListActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_people_list);

    final ActionBar actionBar = getSupportActionBar();
    // set defaults for logo & home up
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayUseLogoEnabled(true);

    FragmentManager fm = getSupportFragmentManager();
    mPeopleListFragment = (PeopleListFragment) fm.findFragmentById(R.id.fragment_people_list);
    mManager.addListener(mStateUpdatedListener);
}

From source file:ca.mudar.mtlaucasou.ui.AboutActivity.java

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

    ((AppHelper) getApplicationContext()).updateUiLanguage();

    FragmentManager fm = getSupportFragmentManager();

    if (fm.findFragmentById(android.R.id.content) == null) {
        AboutFragment about = new AboutFragment();
        fm.beginTransaction().add(android.R.id.content, about).commit();
    }//from  w w w .j a  va2s .co  m

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        getActionBar().setHomeButtonEnabled(true);
    }
}

From source file:com.audiokernel.euphonyrmt.URIHandlerActivity.java

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

    final Intent intent = getIntent();
    final FragmentManager fragmentManager = getSupportFragmentManager();
    final StreamsFragment streamsFragment = (StreamsFragment) fragmentManager
            .findFragmentById(R.id.streamsFragment);

    if (!Intent.ACTION_VIEW.equals(intent.getAction())) {
        finish();//from  w ww  . ja  va2  s  .c o  m
    }

    streamsFragment.addEdit(-1, intent.getDataString());
}

From source file:com.ui.UiFragmentManager.java

public Fragment getFragmentAdd(FragmentManager fragmentManager, BaseFragment baseFragment, int fragmentId) {
    BaseFragment isNullFragement = (BaseFragment) fragmentManager.findFragmentById(fragmentId);
    if (null == isNullFragement) {
        fragmentManager.beginTransaction().add(fragmentId, baseFragment).commit();
    } else {/*  w ww .  ja  va2s .co m*/
        fragmentManager.beginTransaction().attach(baseFragment).commit();
    }
    return (Fragment) fragmentManager.findFragmentById(fragmentId);
}

From source file:com.qubling.sidekick.ui.module.ModuleViewActivity.java

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

    setContentView(R.layout.module_view);

    // Setup BugSense
    Util.setupBugSense(this);

    Intent intent = getIntent();//from  ww  w .ja v a  2s. c o m
    Module module = (Module) intent.getParcelableExtra(EXTRA_MODULE);

    setTitle(module.getName());

    FragmentManager fragmentManager = getSupportFragmentManager();
    ModuleViewFragment fragment = (ModuleViewFragment) fragmentManager
            .findFragmentById(R.id.module_view_fragment);
    fragment.setModule(module);
}

From source file:com.rstar.mobile.simpledemos.DemoQuietTimerActivity.java

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

    FragmentManager fm = getSupportFragmentManager();
    fragment = fm.findFragmentById(fragmentId);

    if (fragment == null) {
        fragment = new InternalFragment();
        fm.beginTransaction().add(fragmentId, fragment).commit();
    }//from   w  w w .j a v  a2  s  .  co  m
}

From source file:com.joulespersecond.seattlebusbot.AgenciesActivity.java

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

    FragmentManager fm = getSupportFragmentManager();

    // Create the list fragment and add it as our sole content.
    if (fm.findFragmentById(android.R.id.content) == null) {
        AgenciesFragment list = new AgenciesFragment();
        fm.beginTransaction().add(android.R.id.content, list).commit();
    }/* w ww  .  j  a  v  a2  s  .  c om*/
}