Java Code Examples for android.support.v4.app.FragmentManager#findFragmentById()
The following examples show how to use
android.support.v4.app.FragmentManager#findFragmentById() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbsSingleFragmentActivity.java From base-imageloader with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(getLayoutId()); FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentById(R.id.id_fragmentContainer); if (fragment == null) { fragment = createFragment(); fm.beginTransaction().add(R.id.id_fragmentContainer, fragment) .commit(); } }
Example 2
Source File: FreightTrackMapActivity.java From ESeal with Apache License 2.0 | 6 votes |
private void attachDeviceWithWebViewFragment() { FragmentManager supportFragmentManager = getSupportFragmentManager(); FreightTrackMapWithWebViewFragment fragment = (FreightTrackMapWithWebViewFragment) supportFragmentManager.findFragmentById(R.id.content_main); if (fragment == null) { fragment = FreightTrackMapWithWebViewFragment.newInstance(mFreight.getId(), mFreight.getName()); ActivityUtils.replaceFragmentToActivity(supportFragmentManager, fragment, R.id.content_main); } boolean mUsingWebView = "zh-CN".equals(LanguageUtil.getLanguage()) ? false : true; new FreightTrackMapWithWebViewPresenter( mUsingWebView, mFreight.getId(), mFreight.getName(), getApplicationContext(), fragment, SchedulerProvider.getInstance()); }
Example 3
Source File: AbsSingleFragmentActivity.java From base-imageloader with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(getLayoutId()); FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentById(R.id.id_fragmentContainer); if (fragment == null) { fragment = createFragment(); fm.beginTransaction().add(R.id.id_fragmentContainer, fragment) .commit(); } }
Example 4
Source File: MainActivity.java From droidkaigi2016 with Apache License 2.0 | 6 votes |
@Override public void onBackStackChanged() { FragmentManager fm = getSupportFragmentManager(); Fragment current = fm.findFragmentById(R.id.content_view); if (current == null) { // no more fragments in the stack. finish. finish(); return; } Page page = Page.forName(current); binding.navView.setCheckedItem(page.getMenuId()); binding.toolbar.setTitle(page.getTitleResId()); toggleToolbarElevation(page.shouldToggleToolbar()); if (current instanceof StackedPageListener) { StackedPageListener l = (StackedPageListener) current; l.onTop(); } }
Example 5
Source File: RecyclerActivity.java From AndroidSamples with Apache License 2.0 | 6 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_recycler); FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentById(R.id.fragment_container); if (fragment == null) { fragment = new RecyFragment(); fm.beginTransaction() .add(R.id.fragment_container, fragment) .commit(); } }
Example 6
Source File: AudioPlayerContainerActivity.java From VCL-Android with Apache License 2.0 | 6 votes |
public void updateLib() { if (mPreventRescan){ mPreventRescan = false; return; } FragmentManager fm = getSupportFragmentManager(); Fragment current = fm.findFragmentById(R.id.fragment_placeholder); if (current != null && current instanceof IRefreshable) ((IRefreshable) current).refresh(); else MediaLibrary.getInstance().scanMediaItems(); Fragment fragment = fm.findFragmentByTag(SidebarAdapter.SidebarEntry.ID_AUDIO); if (fragment != null && !fragment.equals(current)) { ((MediaBrowserFragment)fragment).clear(); } fragment = fm.findFragmentByTag(SidebarAdapter.SidebarEntry.ID_VIDEO); if (fragment != null && !fragment.equals(current)) { ((MediaBrowserFragment)fragment).clear(); } }
Example 7
Source File: MainActivity.java From simple_imageloader with MIT License | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentById(R.id.fragment_container); if (fragment == null) { fragment = new ImagesFragment(); fm.beginTransaction().add(R.id.fragment_container, fragment) .commit(); } initImageLoader(); }
Example 8
Source File: MainActivity.java From ChangeSkin with Apache License 2.0 | 5 votes |
private void initView() { mDrawerLayout = (DrawerLayout) findViewById(R.id.id_drawerLayout); FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentById(R.id.id_left_menu_container); if (fragment == null) { fm.beginTransaction().add(R.id.id_left_menu_container, new MenuLeftFragment()).commit(); } }
Example 9
Source File: LoginActivity.java From state-machine-android with MIT License | 5 votes |
private void showFragment(Fragment fragment) { FragmentManager fragmentManager = getSupportFragmentManager(); Fragment currentFragment = fragmentManager.findFragmentById(R.id.fragment_container); if (currentFragment != null) { return; } FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.replace(R.id.fragment_container, fragment); transaction.commit(); }
Example 10
Source File: FreightTrackMapActivity.java From ESeal with Apache License 2.0 | 5 votes |
private void attachDeviceGoogleMapFragment() { FragmentManager supportFragmentManager = getSupportFragmentManager(); FreightTrackGoogleMapFragment fragment = (FreightTrackGoogleMapFragment) supportFragmentManager.findFragmentById(R.id.content_main); if (fragment == null) { fragment = FreightTrackGoogleMapFragment.newInstance(mFreight.getId(), mFreight.getName()); ActivityUtils.replaceFragmentToActivity(supportFragmentManager, fragment, R.id.content_main); } }
Example 11
Source File: LoaderRetainedSupport.java From V.FlyoutTest with MIT License | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FragmentManager fm = getSupportFragmentManager(); // Create the list fragment and add it as our sole content. if (fm.findFragmentById(android.R.id.content) == null) { CursorLoaderListFragment list = new CursorLoaderListFragment(); fm.beginTransaction().add(android.R.id.content, list).commit(); } }
Example 12
Source File: EditTvShow.java From Mizuu with Apache License 2.0 | 5 votes |
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final String showId = getIntent().getStringExtra("showId"); mToolbarColor = getIntent().getExtras().getInt(IntentKeys.TOOLBAR_COLOR); final FragmentManager fm = getSupportFragmentManager(); if (fm.findFragmentById(android.R.id.content) == null) { fm.beginTransaction().add(android.R.id.content, EditTvShowFragment.newInstance(showId)).commit(); } }
Example 13
Source File: EditTvShowEpisode.java From Mizuu with Apache License 2.0 | 5 votes |
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final String showId = getIntent().getStringExtra("showId"); final int season = getIntent().getIntExtra("season", -1); final int episode = getIntent().getIntExtra("episode", -1); final FragmentManager fm = getSupportFragmentManager(); if (fm.findFragmentById(android.R.id.content) == null) { fm.beginTransaction().add(android.R.id.content, EditTvShowEpisodeFragment.newInstance(showId, season, episode)).commit(); } }
Example 14
Source File: LeftDrawerLayoutActivity.java From Android_Blog_Demos with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_left_drawer_layout); mLeftDrawerLayout = (LeftDrawerLayout) findViewById(R.id.id_drawerlayout); mContentTv = (TextView) findViewById(R.id.id_content_tv); FragmentManager fm = getSupportFragmentManager(); mMenuFragment = (LeftMenuFragment) fm.findFragmentById(R.id.id_container_menu); if (mMenuFragment == null) { fm.beginTransaction().add(R.id.id_container_menu, mMenuFragment = new LeftMenuFragment()).commit(); } mMenuFragment.setOnMenuItemSelectedListener(new LeftMenuFragment.OnMenuItemSelectedListener() { @Override public void menuItemSelected(String title) { mLeftDrawerLayout.closeDrawer(); mContentTv.setText(title); } }); }
Example 15
Source File: MainActivity.java From sensors-samples with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); FragmentManager fm = getSupportFragmentManager(); BatchStepSensorFragment fragment = (BatchStepSensorFragment) fm.findFragmentByTag(FRAGTAG); if (fragment == null) { FragmentTransaction transaction = fm.beginTransaction(); fragment = new BatchStepSensorFragment(); transaction.add(fragment, FRAGTAG); transaction.commit(); } // Use fragment as click listener for cards, but must implement correct interface if (!(fragment instanceof OnCardClickListener)){ throw new ClassCastException("BatchStepSensorFragment must " + "implement OnCardClickListener interface."); } OnCardClickListener clickListener = (OnCardClickListener) fm.findFragmentByTag(FRAGTAG); mRetentionFragment = (StreamRetentionFragment) fm.findFragmentByTag(RETENTION_TAG); if (mRetentionFragment == null) { mRetentionFragment = new StreamRetentionFragment(); fm.beginTransaction().add(mRetentionFragment, RETENTION_TAG).commit(); } else { // If the retention fragment already existed, we need to pull some state. // pull state out CardStreamState state = mRetentionFragment.getCardStream(); // dump it in CardStreamFragment. mCardStreamFragment = (CardStreamFragment) fm.findFragmentById(R.id.fragment_cardstream); mCardStreamFragment.restoreState(state, clickListener); } }
Example 16
Source File: TwitterActivity.java From android-oauth-client with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); super.onCreate(savedInstanceState); FragmentManager fm = getSupportFragmentManager(); if (fm.findFragmentById(android.R.id.content) == null) { TwitterListFragment list = new TwitterListFragment(); fm.beginTransaction().add(android.R.id.content, list).commit(); } }
Example 17
Source File: SingleFragmentActivity.java From AndroidProgramming3e with Apache License 2.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(getLayoutResId()); FragmentManager manager = getSupportFragmentManager(); Fragment fragment = manager.findFragmentById(R.id.fragment_container); if (fragment == null) { fragment = createFragment(); manager.beginTransaction() .add(R.id.fragment_container, fragment) .commit(); } }
Example 18
Source File: SingleFragmentActivity.java From weMessage with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstance){ super.onCreate(savedInstance); setContentView(getLayoutResId()); FragmentManager fragmentManager = getSupportFragmentManager(); Fragment fragment = fragmentManager.findFragmentById(getContainerId()); if (fragment == null){ fragment = createFragment(); fragmentManager.beginTransaction().add(getContainerId(), fragment).commit(); } }
Example 19
Source File: SingleFragmentActivity.java From AndroidProgramming3e with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_fragment); FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentById(R.id.fragment_container); if (fragment == null) { fragment = createFragment(); fm.beginTransaction() .add(R.id.fragment_container, fragment) .commit(); } }
Example 20
Source File: ClassifyFragment.java From android-galaxyzoo with GNU General Public License v3.0 | 4 votes |
private void addOrUpdateChildFragments() { showLoadingInProgress(false); final Bundle arguments = new Bundle(); //TODO? arguments.putString(ARG_USER_ID, // getUserId()); //Obtained in the super class. arguments.putString(ItemFragment.ARG_ITEM_ID, getItemId()); //Add, or update, the nested child fragments. //This can only be done programmatically, not in the layout XML. //See http://developer.android.com/about/versions/android-4.2.html#NestedFragments final FragmentManager fragmentManager = getChildFragmentManager(); SubjectFragment fragmentSubject = (SubjectFragment) fragmentManager.findFragmentById(R.id.child_fragment_subject); if (fragmentSubject == null) { fragmentSubject = new SubjectFragment(); fragmentSubject.setArguments(arguments); fragmentManager.beginTransaction().replace(R.id.child_fragment_subject, fragmentSubject).commit(); } else { //TODO: Is there some more standard method to do this, //to trigger the Fragments' onCreate()? fragmentSubject.setItemId(getItemId()); //We don't wipe the inverted state (setInverted()) because this can happen after rotation, //not just when starting a new classification. fragmentSubject.update(); } QuestionFragment fragmentQuestion = (QuestionFragment) fragmentManager.findFragmentById(R.id.child_fragment_question); if (fragmentQuestion == null) { fragmentQuestion = new QuestionFragment(); fragmentQuestion.setArguments(arguments); fragmentManager.beginTransaction().replace(R.id.child_fragment_question, fragmentQuestion).commit(); } else { //TODO: Is there some more standard method to do this, //to trigger the Fragments' onCreate()? fragmentQuestion.setGroupId(null); //Avoid any chance of us using the wrong groups's decision tree. fragmentQuestion.setItemId(getItemId()); //This will trigger a later UI update of the fragment. } }