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:edu.cmu.sv.lifelogger.FBLoginActivity.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  ww  .ja  v a 2 s .  c o m

    setContentView(R.layout.activity_login);

    loginButton = (LoginButton) findViewById(R.id.authButton);
    // set permission list, Don't foeget to add email
    loginButton.setReadPermissions(Arrays.asList("basic_info", "email"));
    loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
        @Override
        public void onUserInfoFetched(GraphUser user) {
            FBLoginActivity.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);
            }
        }
    });

    canPresentShareDialog = FacebookDialog.canPresentShareDialog(this,
            FacebookDialog.ShareDialogFeature.SHARE_DIALOG);
}

From source file:com.contralabs.inmap.activities.MainActivity.java

private void configureFragments() {
    FragmentManager fm = getSupportFragmentManager();

    mStoreCategoryListFragment = (StoreCategoryListFragment) fm.findFragmentById(R.id.fragment_categorylist);
    mStoreCategoryListFragment.setOnStoreCategoryChangedListener(this);

    mInfrastructureBarFragment = (InfrastructureBarFragment) fm.findFragmentById(R.id.fragment_infrabar);
    mInfrastructureBarFragment.setOnInfrastructureCategoryChangeListener(this);

    mStoreListFragment = (StoreListFragment) fm.findFragmentById(R.id.fragment_storelist);
    mStoreListFragment.setOnStoreSelectedListener(this);
    mStoreListFragment.setStoreListController(this);

    //mPeopleInsideFragment = (PeopleInsideFragment) fm.findFragmentById(R.id.fragment_peopleinside);
}

From source file:com.fb.sample.samplelogin.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);
    }/* w ww  .  ja v  a  2 s.  c o m*/

    setContentView(R.layout.main);

    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);
            }
        }
    });

    // Can we present the share dialog for regular links?
    canPresentShareDialog = FacebookDialog.canPresentShareDialog(this,
            FacebookDialog.ShareDialogFeature.SHARE_DIALOG);
    // Can we present the share dialog for photos?
    canPresentShareDialogWithPhotos = FacebookDialog.canPresentShareDialog(this,
            FacebookDialog.ShareDialogFeature.PHOTOS);
}

From source file:com.xiaoYue.facedetection.HelloFacebookSampleActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    uiHelper = new UiLifecycleHelper(this, callback);
    uiHelper.onCreate(savedInstanceState);
    Intent datagetintent = getIntent();//from  www .  j  a v  a 2  s  . c  o  m
    fileuri = datagetintent.getStringExtra("serchresult");
    if (savedInstanceState != null) {
        String name = savedInstanceState.getString(PENDING_ACTION_BUNDLE_KEY);
        pendingAction = PendingAction.valueOf(name);
    }

    setContentView(R.layout.main);

    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);
            }
        }
    });

    // Can we present the share dialog for regular links?
    canPresentShareDialog = FacebookDialog.canPresentShareDialog(this,
            FacebookDialog.ShareDialogFeature.SHARE_DIALOG);
    // Can we present the share dialog for photos?
    canPresentShareDialogWithPhotos = FacebookDialog.canPresentShareDialog(this,
            FacebookDialog.ShareDialogFeature.PHOTOS);
}

From source file:ca.appvelopers.mcgillmobile.ui.MapActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map);
    ButterKnife.bind(this);
    App.component(this).inject(this);
    analytics.sendScreen("Map");

    //Set up the initial information
    places = new ArrayList<>();
    shownPlaces = new ArrayList<>();
    searchString = "";
    type = new PlaceType(false);

    FormGenerator fg = FormGenerator.bind(this, container);

    // Icon coloring
    int red = ContextCompat.getColor(this, R.color.red);
    Utils.setTint(directions, 0, red);//  ww  w.j  a  v  a 2s  .  com
    Utils.setTint(favorite, 0, red);

    //Set up the place filter
    fg.text(type.getString(this, languagePref.get())).leftIcon(R.drawable.ic_location)
            .rightIcon(R.drawable.ic_chevron_right, Color.GRAY).onClick(new TextViewFormItem.OnClickListener() {
                @Override
                public void onClick(final TextViewFormItem item) {
                    DialogUtils.list(MapActivity.this, R.string.map_filter,
                            new PlaceTypeListAdapter(MapActivity.this, type) {
                                @Override
                                public void onPlaceTypeSelected(PlaceType type) {
                                    MapActivity.this.type = type;

                                    //Update the text
                                    item.view().setText(
                                            type.getString(MapActivity.this, languagePreference.get()));

                                    //Update the filtered places
                                    filterByCategory();
                                }
                            });
                }
            }).build();

    FragmentManager manager = getSupportFragmentManager();
    //Get the MapFragment
    SupportMapFragment fragment = (SupportMapFragment) manager.findFragmentById(R.id.map);
    //If it's null, initialize it and put it in its view
    if (fragment == null) {
        fragment = SupportMapFragment.newInstance();
        manager.beginTransaction().replace(R.id.map, fragment).addToBackStack(null).commit();
    }

    fragment.getMapAsync(this);
}

From source file:com.smartcontroller.clientside.FacebookShareActivity.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);
    }/*w  w  w  .  j  a va  2s  . c  o m*/

    setContentView(R.layout.activity_fb);

    loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
        @Override
        public void onUserInfoFetched(GraphUser user) {
            FacebookShareActivity.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);
            }
        }
    });

    canPresentShareDialog = FacebookDialog.canPresentShareDialog(this,
            FacebookDialog.ShareDialogFeature.SHARE_DIALOG);
}

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

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

    Intent intent = getIntent();/*  w  w w.j  a v  a2s. c om*/

    Uri data = intent.getData();
    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction t = fm.beginTransaction();

    Fragment bookmarkFrag;

    if (fm.findFragmentById(R.id.listcontent) == null) {
        if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
            Bundle searchData = intent.getBundleExtra(SearchManager.APP_DATA);

            if (searchData != null) {
                tagname = searchData.getString("tagname");
                username = searchData.getString("username");
                unread = searchData.getBoolean("unread");
            }

            query = intent.getStringExtra(SearchManager.QUERY);

            if (intent.hasExtra("username")) {
                username = intent.getStringExtra("username");
            }

            if (data != null && data.getUserInfo() != null) {
                username = data.getUserInfo();
            }
        } else {
            if (data != null) {
                if (data.getUserInfo() != "") {
                    username = data.getUserInfo();
                } else
                    username = mAccount.name;
                tagname = data.getQueryParameter("tagname");
                unread = data.getQueryParameter("unread") != null;
                path = data.getPath();
            }
        }

        if (isMyself()) {
            bookmarkFrag = new BrowseBookmarksFragment();
        } else {
            bookmarkFrag = new BrowseBookmarkFeedFragment();
        }

        t.add(R.id.listcontent, bookmarkFrag);
    } else {
        if (savedInstanceState != null) {
            username = savedInstanceState.getString(STATE_USERNAME);
            tagname = savedInstanceState.getString(STATE_TAGNAME);
            unread = savedInstanceState.getBoolean(STATE_UNREAD);
            query = savedInstanceState.getString(STATE_QUERY);
            path = savedInstanceState.getString(STATE_PATH);
        }

        bookmarkFrag = fm.findFragmentById(R.id.listcontent);
    }

    if (isMyself()) {
        if (query != null && !query.equals("")) {
            ((BrowseBookmarksFragment) bookmarkFrag).setSearchQuery(query, username, tagname, unread);
        } else {
            ((BrowseBookmarksFragment) bookmarkFrag).setQuery(username, tagname, unread);
        }
    } else {
        if (query != null && !query.equals("")) {
            ((BrowseBookmarkFeedFragment) bookmarkFrag).setQuery(username, tagname);
        } else {
            ((BrowseBookmarkFeedFragment) bookmarkFrag).setQuery(username, query);
        }
    }

    BrowseTagsFragment tagFrag = (BrowseTagsFragment) fm.findFragmentById(R.id.tagcontent);
    if (tagFrag != null) {
        tagFrag.setAccount(username);
    }

    if (path != null && path.contains("tags")) {
        t.hide(fm.findFragmentById(R.id.maincontent));
        findViewById(R.id.panel_collapse_button).setVisibility(View.GONE);
    } else {
        if (tagFrag != null) {
            t.hide(tagFrag);
        }
    }

    Fragment addFrag = fm.findFragmentById(R.id.addcontent);
    if (addFrag != null) {
        t.hide(addFrag);
    }

    t.commit();
}

From source file:com.wicom.magazine.SocialActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    uiHelper = new UiLifecycleHelper(this, callback);
    uiHelper.onCreate(savedInstanceState);

    setContentView(R.layout.activity_social);

    imageName = getIntent().getStringExtra(BundleConstants.GALLERY_ITEM_NAME);

    ZipResourceFile expansionFile = ExpansionFileHolder.getInstance(getApplicationContext()).getExpansionFile();
    InputStream fileStream = null;
    if (expansionFile != null) {

        try {//from w  ww .j a  v  a 2s . c o  m
            int orientation = getResources().getConfiguration().orientation;

            if (orientation == 1) {
                fileStream = expansionFile.getInputStream("drawable/" + imageName + "v.png");
            }
            if (fileStream == null) {
                fileStream = expansionFile.getInputStream("drawable/" + imageName + ".png");
            }

            ((ImageView) findViewById(R.id.pictureToShare))
                    .setImageBitmap(ImageResizer.decodeSampledBitmapFromResource(fileStream, 800, 600));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    if (savedInstanceState != null) {
        String name = savedInstanceState.getString(PENDING_ACTION_BUNDLE_KEY);
        pendingAction = PendingAction.valueOf(name);
    }

    postPhotoButton = (Button) findViewById(R.id.postPhotoButton);
    postPhotoButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickPostPhoto();
        }
    });

    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);
            }
        }
    });

    // Can we present the share dialog for regular links?
    canPresentShareDialog = FacebookDialog.canPresentShareDialog(this,
            FacebookDialog.ShareDialogFeature.SHARE_DIALOG);
    // Can we present the share dialog for photos?
    canPresentShareDialogWithPhotos = FacebookDialog.canPresentShareDialog(this,
            FacebookDialog.ShareDialogFeature.PHOTOS);
}

From source file:com.meetingninja.csse.MainActivity.java

/** Swaps fragments in the main content view */
private void selectItem(int position) {
    // Save the state of the current fragment
    session.setPage(position);//from w w w. j a v  a  2s.  c  om
    FragmentManager fm = getSupportFragmentManager();
    final Fragment currentPage = fm.findFragmentById(R.id.content_frame);

    Fragment nextPage = null;
    Bundle args = new Bundle();
    String tag = "default";

    DrawerLabel clickedLabel = DrawerLabel.values()[position];
    switch (clickedLabel) {
    case MEETINGS:
        nextPage = new MeetingsFragment();
        frag_meetings = (MeetingsFragment) nextPage;
        break;
    case NOTES:
        nextPage = new NotesFragment();
        frag_notes = (NotesFragment) nextPage;
        break;
    case TASKS:
        // nextPage = new TasksFragment();
        nextPage = TasksFragment.getInstance();
        frag_tasks = new TasksFragment();
        break;
    case PROFILE:
        nextPage = new ProfileFragment();
        frag_profile = (ProfileFragment) nextPage;
        break;
    case GROUPS:
        nextPage = new GroupsFragment();
        frag_groups = (GroupsFragment) nextPage;
        break;
    case PROJECTS:
        nextPage = ProjectFragment.getInstance();
        // args.putString("Content", "TODO: Projects Page");
        // nextPage.setArguments(args);
        frag_project = new ProjectFragment();
        break;
    case CONTACTS:
        // fragment = new DummyFragment();
        // args.putString("Content", "TODO: Groups Page");
        // fragment.setArguments(args);
        nextPage = new UserListFragment();
        break;
    // case SETTINGS:
    // nextPage = SearchableUserFragment.getInstance();
    // // args.putString("Content", "TODO: Settings Page");
    // // fragment.setArguments(args);
    // break;
    // case ABOUT:
    // nextPage = new DummyFragment();
    // args.putString("Content", "TODO: About Page");
    // nextPage.setArguments(args);
    // break;
    case LOGOUT:
        logout();
        break;
    default:
        Log.e(TAG + "drawerClicked", clickedLabel.toString() + " is not a valid page");
        break;
    }

    if (nextPage != null) {
        FragmentTransaction ft = fm.beginTransaction();
        // if (currentPage != null)
        // ft.hide(currentPage);

        // if (fm.findFragmentByTag(tag) == null) {
        // ft.add(R.id.content_frame, nextPage, tag).commit();
        // } else {
        // ft.show(fm.findFragmentByTag(tag));
        // Insert the fragment by replacing any existing fragment
        ft.replace(R.id.content_frame, nextPage).commit();
        // }

        // Highlight the selected item, update the title, and close the
        // drawer
        leftDrawerList.setItemChecked(position, true);
        leftDrawerList.setSelection(position);
        setTitle(leftDrawerItemNames[position]);
        drawerLayout.closeDrawer(leftDrawerList);
    } else {
        // error in creating fragment
        Log.e(TAG, "Error in creating fragment");
    }
}

From source file:com.money.manager.ex.assetallocation.editor.AssetAllocationEditorActivity.java

private void showAssetClass(AssetClass assetClass) {
    if (assetClass == null)
        return;/* www .j  a  va2s.c  o  m*/

    // Round to decimals from the base currency.
    CurrencyService currencyService = new CurrencyService(this);
    int scale = currencyService.getBaseCurrency().getScale();
    int decimals = new NumericHelper(this).getNumberOfDecimals(scale);

    // show the fragment
    FragmentManager fm = getSupportFragmentManager();
    AssetAllocationContentsFragment fragment = AssetAllocationContentsFragment.create(assetClass.getId(),
            decimals, this.assetAllocation);

    String tag = assetClass.getId() != null ? assetClass.getId().toString() : "root";

    FragmentTransaction transaction = fm.beginTransaction();

    if (fm.findFragmentById(R.id.content) == null) {
        tag = AssetAllocationContentsFragment.class.getSimpleName();

        //            transaction.add(R.id.content, fragment, tag)
        transaction.replace(R.id.content, fragment, tag).commit();
        // the initial fragment does not go onto back stack.
    } else {
        // Replace existing fragment. Always use replace instead of add?
        transaction.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left, R.anim.slide_in_right,
                R.anim.slide_out_left);
        transaction.replace(R.id.content, fragment, tag);
        transaction.addToBackStack(null);
        transaction.commit();
    }
}