List of usage examples for android.support.v4.app FragmentManager findFragmentById
public abstract Fragment findFragmentById(int id);
From source file:net.oremland.rss.reader.MainActivity.java
private Fragment getFragment(int id) { FragmentManager manager = getSupportFragmentManager(); Fragment fragment = manager.findFragmentByTag(this.getFragmentIdAsString(id)); if (fragment == null) { fragment = manager.findFragmentById(id); }//from w ww. j a v a 2s . c o m return fragment; }
From source file:com.murrayc.galaxyzoo.app.SubjectViewerActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (TextUtils.isEmpty(getItemId())) { setItemId(ItemsContentProvider.URI_PART_ITEM_ID_NEXT); }/* w ww . j av a 2 s. c o m*/ setContentView(R.layout.activity_classify); UiUtils.showToolbar(this); // savedInstanceState is non-null when there is fragment state // saved from previous configurations of this activity // (e.g. when rotating the screen from portrait to landscape). // In this case, the fragment will automatically be re-added // to its container so we don't need to manually add it. // For more information, see the Fragments API guide at: // // http://developer.android.com/guide/components/fragments.html // if (savedInstanceState == null) { final FragmentManager fragmentManager = getSupportFragmentManager(); if (fragmentManager != null) { //We check to see if the fragment exists already, //because apparently it sometimes does exist already when the app has been //in the background for some time, //at least on Android 5.0 (Lollipop) SubjectViewerFragment fragment = (SubjectViewerFragment) fragmentManager .findFragmentById(R.id.container); if (fragment == null) { // Create the detail fragment and add it to the activity // using a fragment transaction. final Bundle arguments = new Bundle(); arguments.putString(ItemFragment.ARG_ITEM_ID, getItemId()); fragment = new SubjectViewerFragment(); fragment.setArguments(arguments); fragmentManager.beginTransaction().replace(R.id.container, fragment).commit(); } else { Log.info("SubjectViewerActivity.onCreate(): The SubjectViewerFragment already existed."); fragment.setItemId(getItemId()); fragment.update(); } } } showUpButton(); }
From source file:m2.android.archetype.example.facebook.HelloFacebookSampleActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); uiHelper = new UiLifecycleHelper(this, callback); uiHelper.onCreate(savedInstanceState); if (savedInstanceState != null) { String name = savedInstanceState.getString(PENDING_ACTION_BUNDLE_KEY); pendingAction = PendingAction.valueOf(name); }/*from w w w. ja v a 2s. co m*/ setContentView(R.layout.activity_hello_facebook); loginButton = (LoginButton) findViewById(R.id.login_button); loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() { @Override public void onUserInfoFetched(GraphUser user) { HelloFacebookSampleActivity.this.user = user; updateUI(); // It's possible that we were waiting for this.user to be populated in order to post a // status update. handlePendingAction(); } }); profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture); greeting = (TextView) findViewById(R.id.greeting); postStatusUpdateButton = (Button) findViewById(R.id.postStatusUpdateButton); postStatusUpdateButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickPostStatusUpdate(); } }); postPhotoButton = (Button) findViewById(R.id.postPhotoButton); postPhotoButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickPostPhoto(); } }); pickFriendsButton = (Button) findViewById(R.id.pickFriendsButton); pickFriendsButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickPickFriends(); } }); pickPlaceButton = (Button) findViewById(R.id.pickPlaceButton); pickPlaceButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickPickPlace(); } }); 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); if (fragment instanceof FriendPickerFragment) { setFriendPickerListeners((FriendPickerFragment) fragment); } else if (fragment instanceof PlacePickerFragment) { setPlacePickerListeners((PlacePickerFragment) fragment); } } // 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); } } }); }
From source file:com.murrayc.galaxyzoo.app.ClassifyFragment.java
public void update() { final Activity activity = getActivity(); if (activity == null) return;/*from www.j a v a 2s . c o m*/ if (TextUtils.equals(getItemId(), ItemsContentProvider.URI_PART_ITEM_ID_NEXT)) { /* * Initializes the CursorLoader. The LOADER_ID_NEXT_ID value is eventually passed * to onCreateLoader(). * We use restartLoader(), instead of initLoader(), * so we can refresh this fragment to show a different subject, * even when using the same query ("next") to do that. * * However, we don't start another "next" request when one is already in progress, * because then we would waste the first one and slow both down. * This can happen during resume. */ if (!mGetNextInProgress) { mGetNextInProgress = true; //Don't stay inverted after a previous classification. final FragmentManager fragmentManager = getChildFragmentManager(); final SubjectFragment fragmentSubject = (SubjectFragment) fragmentManager .findFragmentById(R.id.child_fragment_subject); if (fragmentSubject != null) { fragmentSubject.setInverted(false); } //Get the actual ID and other details: getLoaderManager().restartLoader(LOADER_ID_NEXT_ID, null, this); } } else { //Add, or update, the child fragments already, because we know the Item IDs: addOrUpdateChildFragments(); } }
From source file:com.murrayc.galaxyzoo.app.QuestionHelpActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_question_help); UiUtils.showToolbar(this); final Intent intent = getIntent(); setQuestionId(intent.getStringExtra(BaseQuestionFragment.ARG_QUESTION_ID)); setGroupId(intent.getStringExtra(QuestionHelpFragment.ARG_GROUP_ID)); // savedInstanceState is non-null when there is fragment state // saved from previous configurations of this activity // (e.g. when rotating the screen from portrait to landscape). // In this case, the fragment will automatically be re-added // to its container so we don't need to manually add it. // For more information, see the Fragments API guide at: ///* w w w. jav a 2 s . co m*/ // http://developer.android.com/guide/components/fragments.html // if (savedInstanceState == null) { final FragmentManager fragmentManager = getSupportFragmentManager(); if (fragmentManager != null) { //We check to see if the fragment exists already, //because apparently it sometimes does exist already when the app has been //in the background for some time, //at least on Android 5.0 (Lollipop) QuestionHelpFragment fragment = (QuestionHelpFragment) fragmentManager .findFragmentById(R.id.container); if (fragment == null) { // Create the detail fragment and add it to the activity // using a fragment transaction. final Bundle arguments = new Bundle(); arguments.putString(BaseQuestionFragment.ARG_QUESTION_ID, getQuestionId()); arguments.putString(QuestionHelpFragment.ARG_GROUP_ID, getGroupId()); fragment = new QuestionHelpFragment(); fragment.setArguments(arguments); fragmentManager.beginTransaction().replace(R.id.container, fragment).commit(); } else { Log.info("QuestionHelpActivity.onCreate(): The QuestionHelpFragment already existed."); fragment.setQuestionId(getQuestionId()); fragment.setGroupId(getGroupId()); fragment.update(); } } } showUpButton(); }
From source file:com.google.android.apps.iosched.ui.tablet.SessionsVendorsMultiPaneActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { if (BeamUtils.wasLaunchedThroughBeamFirstTime(this, getIntent())) { BeamUtils.setBeamUnlocked(this); showFirstBeamDialog();/*from ww w . j a v a 2s . co m*/ } BeamUtils.tryUpdateIntentFromBeam(this); super.onCreate(savedInstanceState); trySetBeamCallback(); setContentView(R.layout.activity_sessions_vendors); final FragmentManager fm = getSupportFragmentManager(); mTracksDropdownFragment = (TracksDropdownFragment) fm.findFragmentById(R.id.fragment_tracks_dropdown); mShowHideMasterLayout = (ShowHideMasterLayout) findViewById(R.id.show_hide_master_layout); if (mShowHideMasterLayout != null) { mShowHideMasterLayout.setFlingToExposeMasterEnabled(true); } routeIntent(getIntent(), savedInstanceState != null); if (savedInstanceState != null) { if (mFullUI) { getSupportActionBar().setSelectedNavigationItem(TracksDropdownFragment.VIEW_TYPE_SESSIONS .equals(savedInstanceState.getString(STATE_VIEW_TYPE)) ? 0 : 1); } mDetailFragment = fm.findFragmentById(R.id.fragment_container_detail); updateDetailBackground(); } // This flag prevents onTabSelected from triggering extra master pane reloads // unless it's actually being triggered by the user (and not automatically by // the system) mInitialTabSelect = false; EasyTracker.getTracker().setContext(this); }
From source file:com.example.ramesh.p2pfileshare.ClientActivity.java
public void displayPeers(final WifiP2pDeviceList peers) { //Dialog to show errors/status final AlertDialog.Builder dialog = new AlertDialog.Builder(this); dialog.setTitle("WiFi Direct File Transfer"); //Get list view //ListView peerView = (ListView) findViewById(R.id.peers_listview); //--version2 //Make array list ArrayList<String> peersStringArrayList = new ArrayList<String>(); //Fill array list with strings of peer names for (WifiP2pDevice wd : peers.getDeviceList()) { peersStringArrayList.add(wd.deviceName); }//from w w w.j a v a 2 s. c o m //Set list view as clickable //peerView.setClickable(true); --version2 String[] peersList = new String[peersStringArrayList.size()]; peersList = peersStringArrayList.toArray(peersList); Log.v("WIFIP2PNEW", "Total servers showing " + peersList.length); Bundle bundle = new Bundle(); bundle.putStringArray("server_names", peersList); ServerListFragment serverListFragment = new ServerListFragment(); serverListFragment.setArguments(bundle); FragmentManager fm = getSupportFragmentManager(); ServerListFragment prevFrag = (ServerListFragment) fm.findFragmentById(R.id.myclientlayout); if (prevFrag != null) { fm.beginTransaction().remove(prevFrag).commit(); Log.v("WIFIP2PNEW", "Prevs fargment found so removing"); } else { Log.v("WIFIP2PNEW", "No Prevs fargment found so creating new one"); } fm.beginTransaction().add(R.id.myclientlayout, serverListFragment, "myfragement").commit(); //Make adapter to connect peer data to list view /*ArrayAdapter arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, peersStringArrayList.toArray()); //--version2 //Show peer data in listview peerView.setAdapter(arrayAdapter); peerView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View view, int arg2,long arg3) { //Get string from textview TextView tv = (TextView) view; WifiP2pDevice device = null; //Search all known peers for matching name for(WifiP2pDevice wd : peers.getDeviceList()) { if(wd.deviceName.equals(tv.getText())) device = wd; } if(device != null) { //Connect to selected peer connectToPeer(device); } else { dialog.setMessage("Failed"); dialog.show(); } } // TODO Auto-generated method stub }); //--version2 */ }
From source file:com.erevacation.challenge.ui.base.navigator.BaseNavigator.java
private void replaceFragmentInternalWithSharedElement(FragmentManager fm, @IdRes int containerId, Fragment fragment, String fragmentTag, Bundle args, boolean addToBackStack, String backStackTag, View sharedElement, String transitionName) { if (args != null) { fragment.setArguments(args);/*from www . j a va 2s .c o m*/ } if (addToBackStack) { Fragment replacedFragment = fm.findFragmentById(containerId); if (replacedFragment != null) { fm.saveFragmentInstanceState(replacedFragment); } mFragmentBackStackAnimations.apply(fm.beginTransaction()) .addSharedElement(sharedElement, transitionName).add(containerId, fragment, fragmentTag) .addToBackStack(backStackTag).commit(); fm.executePendingTransactions(); } else { mFragmentAnimations.apply(fm.beginTransaction()).replace(containerId, fragment, fragmentTag) .commitNow(); } }
From source file:com.erevacation.reactiveanimations.ui.base.navigator.BaseNavigator.java
private void replaceFragmentInternalWithSharedElement(FragmentManager fm, @IdRes int containerId, Fragment fragment, String fragmentTag, Bundle args, boolean addToBackStack, String backStackTag, View sharedElement, String transitionName) { if (args != null) { fragment.setArguments(args);/*w w w . j a v a 2 s. co m*/ } if (addToBackStack) { Fragment replacedFragment = fm.findFragmentById(containerId); if (replacedFragment != null) { fm.saveFragmentInstanceState(replacedFragment); } mFragmentBackStackAnimations.apply(fm.beginTransaction()) .addSharedElement(sharedElement, transitionName).replace(containerId, fragment, fragmentTag) .addToBackStack(backStackTag).commit(); fm.executePendingTransactions(); } else { mFragmentAnimations.apply(fm.beginTransaction()).replace(containerId, fragment, fragmentTag) .commitNow(); } }
From source file:org.droidparts.activity.TabbedFragmentActivity.java
private void showFragmentsForCurrentTab(FragmentTransaction ft) { int currTabPos = getCurrentTab(); FragmentManager fm = getSupportFragmentManager(); if (enterAnimation != 0 && exitAnimation != 0) { ft.setCustomAnimations(enterAnimation, exitAnimation); }/* w ww . j ava 2s . c o m*/ for (int tabPos = 0; tabPos < fragmentsOnTab.size(); tabPos++) { boolean isCurrTab = (tabPos == currTabPos); int[] tabFragments = fragmentsOnTab.get(tabPos); for (int fragmentId : tabFragments) { Fragment fragment = fm.findFragmentById(fragmentId); if (fragment != null) { if (isCurrTab) { if (!manuallyHiddenFragments.contains(fragmentId)) { ft.show(fragment); } } else { ft.hide(fragment); } } } } }