Example usage for android.support.v4.app FragmentTransaction hide

List of usage examples for android.support.v4.app FragmentTransaction hide

Introduction

In this page you can find the example usage for android.support.v4.app FragmentTransaction hide.

Prototype

public abstract FragmentTransaction hide(Fragment fragment);

Source Link

Document

Hides an existing fragment.

Usage

From source file:com.smile.moment.ui.activity.MainActivity.java

@Override
public void onTabSelected(int position, boolean wasSelected) {
    currentPosition = position;/*  w w w  .  j a  va  2s  .  c  om*/
    if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
        drawerLayout.closeDrawer(GravityCompat.START);
    }
    switch (position) {
    case 0:
        toolbar.setTitle(context.getString(R.string.navigation_bottom_image_text));
        break;
    case 1:
        toolbar.setTitle(context.getString(R.string.navigation_bottom_voice));
        break;
    case 2:
        toolbar.setTitle(context.getString(R.string.navigation_bottom_joke));
        break;
    default:
        toolbar.setTitle(context.getString(R.string.navigation_bottom_image_text));
        break;
    }

    FragmentTransaction trx = getSupportFragmentManager().beginTransaction();
    for (int i = 0; i < fragments.length; i++) {
        if (i == position) {
            if (!fragments[position].isAdded()) {
                trx.add(R.id.container, fragments[position]);
            }
            trx.show(fragments[i]).commitAllowingStateLoss();
        } else {
            trx.hide(fragments[i]);
        }
    }
}

From source file:com.easemob.chatuidemo.ui.main.MainActivity.java

/**
 * button//from  www . j  av a2 s  .  co m
 * 
 * @param view
 */
public void onTabClicked(View view) {
    int i = view.getId();
    if (i == R.id.btn_conversation) {
        index = 0;

    } else if (i == R.id.btn_address_list) {
        index = 1;

    } else if (i == R.id.btn_setting) {
        index = 2;

    }
    if (currentTabIndex != index) {
        FragmentTransaction trx = getSupportFragmentManager().beginTransaction();
        trx.hide(fragments[currentTabIndex]);
        if (!fragments[index].isAdded()) {
            trx.add(R.id.fragment_container, fragments[index]);
        }
        trx.show(fragments[index]).commit();
    }
    mTabs[currentTabIndex].setSelected(false);
    // ?tab?
    mTabs[index].setSelected(true);
    currentTabIndex = index;
}

From source file:com.example.android.threadsample.PhotoThumbnailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup viewGroup, Bundle bundle) {

    // Always call the super method first
    super.onCreateView(inflater, viewGroup, bundle);

    /*//  ww  w  . java  2 s . c  om
     * Inflates the View from the gridlist layout file, using the layout parameters in
     * "viewGroup"
     */
    View localView = inflater.inflate(R.layout.gridlist, viewGroup, false);

    // Sets the View's data adapter to be a new GridViewAdapter
    mAdapter = new GridViewAdapter(getActivity());

    // Gets a handle to the GridView in the layout
    mGridView = ((GridView) localView.findViewById(android.R.id.list));

    // Instantiates a DisplayMetrics object
    DisplayMetrics localDisplayMetrics = new DisplayMetrics();

    // Gets the current display metrics from the current Window
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(localDisplayMetrics);

    /*
     * Gets the dp value from the thumbSize resource as an integer in dps. The value can
     * be adjusted for specific display sizes, etc. in the dimens.xml file for a particular
     * values-<qualifier> directory
     */
    int pixelSize = getResources().getDimensionPixelSize(R.dimen.thumbSize);

    /*
     * Calculates a width scale factor from the pixel width of the current display and the
     * desired pixel size
     */
    int widthScale = localDisplayMetrics.widthPixels / pixelSize;

    // Calculates the grid column width
    mColumnWidth = (localDisplayMetrics.widthPixels / widthScale);

    // Sets the GridView's column width
    mGridView.setColumnWidth(mColumnWidth);

    // Starts by setting the GridView to have no columns
    mGridView.setNumColumns(-1);

    // Sets the GridView's data adapter
    mGridView.setAdapter(mAdapter);

    /*
     * Sets the GridView's click listener to be this class. As a result, when users click the
     * GridView, PhotoThumbnailFragment.onClick() is invoked.
     */
    mGridView.setOnItemClickListener(this);

    /*
     * Sets the "empty" View for the layout. If there's nothing to show, a ProgressBar
     * is displayed.
     */
    mGridView.setEmptyView(localView.findViewById(R.id.progressRoot));

    // Sets a dark background to show when no image is queued to be downloaded
    mEmptyDrawable = getResources().getDrawable(R.drawable.imagenotqueued);

    // Initializes the CursorLoader
    getLoaderManager().initLoader(URL_LOADER, null, this);

    /*
     * Creates a new Intent to send to the download IntentService. The Intent contains the
     * URL of the Picasa feature picture RSS feed
     */
    mServiceIntent = new Intent(getActivity(), RSSPullService.class).setData(Uri.parse(PICASA_RSS_URL));

    // If there's no pre-existing state for this Fragment
    if (bundle == null) {
        // If the data wasn't previously loaded
        if (!this.mIsLoaded) {
            // Starts the IntentService to download the RSS feed data
            getActivity().startService(mServiceIntent);
        }

        // If this Fragment existed previously, gets its state
    } else if (bundle.getBoolean(STATE_IS_HIDDEN, false)) {

        // Begins a transaction
        FragmentTransaction localFragmentTransaction = getFragmentManager().beginTransaction();

        // Hides the Fragment
        localFragmentTransaction.hide(this);

        // Commits the transaction
        localFragmentTransaction.commit();
    }

    // Returns the View inflated from the layout
    return localView;
}

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

public void onBookmarkEdit(Bookmark b) {
    if (b != null) {
        if (findViewById(R.id.maincontent) != null) {
            AddBookmarkFragment addFrag = (AddBookmarkFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.addcontent);
            addFrag.loadBookmark(b, null);
            addFrag.refreshView();/*from  w w w .  j a va 2  s .  c  o m*/
            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
            if (getSupportFragmentManager().findFragmentById(R.id.tagcontent).isVisible()) {
                transaction.hide(getSupportFragmentManager().findFragmentById(R.id.tagcontent));
                transaction.show(getSupportFragmentManager().findFragmentById(R.id.maincontent));
                transaction.addToBackStack(null);
            }
            transaction.show(getSupportFragmentManager().findFragmentById(R.id.addcontent));
            transaction.commit();
            transaction = getSupportFragmentManager().beginTransaction();
            transaction.hide(getSupportFragmentManager().findFragmentById(R.id.maincontent));
            transaction.commit();
        } else {
            startActivity(IntentHelper.EditBookmark(b, mAccount.name, this));
        }
    }
}

From source file:com.android.transmart.PlaceActivity.java

/**
 * Updates (or displays) the venue detail Fragment when a venue is selected
 * (normally by clicking a place on the Place List.
 * @param reference Place Reference//from  ww w .  j a va 2  s.  c o  m
 * @param id Place Identifier
 */
public void selectDetail(String reference, String id) {
    // If the layout includes a single "main fragment container" then
    // we want to hide the List Fragment and display the Detail Fragment.
    // A back-button click should reverse this operation.
    // This is the phone-portrait mode.
    if (findViewById(R.id.main_fragment_container) != null) {
        placeDetailFragment = PlaceDetailFragment.newInstance(reference, id);
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction ft = fragmentManager.beginTransaction();
        ft.addToBackStack(null);
        if (checkinFragment != null)
            ft.hide(checkinFragment);
        ft.hide(placeListFragment);
        ft.replace(R.id.main_fragment_container, placeDetailFragment);
        ft.show(placeDetailFragment);
        ft.commit();
        // Otherwise the Detail Fragment is already visible and we can
        // Simply replace the previous Fragment with a new one for the
        // selected Place.
    } else {
        placeDetailFragment = PlaceDetailFragment.newInstance(reference, id);
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction ft = fragmentManager.beginTransaction();
        ft.disallowAddToBackStack();
        ft.replace(R.id.detail_fragment_container, placeDetailFragment);
        ft.commit();
    }
}

From source file:com.facebook.android.friendsmash.HomeActivity.java

private void showFragment(int fragmentIndex, boolean addToBackStack) {
    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction transaction = fm.beginTransaction();
    for (int i = 0; i < fragments.length; i++) {
        if (i == fragmentIndex) {
            transaction.show(fragments[i]);
        } else {/*from  w  w  w.j  ava 2 s.com*/
            transaction.hide(fragments[i]);
        }
    }
    if (addToBackStack) {
        transaction.addToBackStack(null);
    }
    transaction.commit();

    // Do other changes depending on the fragment that is now showing
    if (FriendSmashApplication.IS_SOCIAL) {
        switch (fragmentIndex) {
        case FB_LOGGED_OUT_HOME:
            // Hide the progressContainer in FBLoggedOutHomeFragment 
            if (fragments[FB_LOGGED_OUT_HOME] != null
                    && ((FBLoggedOutHomeFragment) fragments[FB_LOGGED_OUT_HOME]) != null) {
                ((FBLoggedOutHomeFragment) fragments[FB_LOGGED_OUT_HOME]).progressContainer
                        .setVisibility(View.INVISIBLE);
            }
            // Set the loggedIn attribute
            ((FriendSmashApplication) getApplication()).setLoggedIn(false);
            break;
        case HOME:
            // Update the youScoredTextView in HomeFragment
            if (fragments[HOME] != null) {
                ((HomeFragment) fragments[HOME]).updateYouScoredTextView();
                ((HomeFragment) fragments[HOME]).updateButtonVisibility();
            }
            // Set the loggedIn attribute
            ((FriendSmashApplication) getApplication()).setLoggedIn(true);
            break;
        }
    }
}

From source file:com.lugia.timetable.MasterActivity.java

public boolean onNavigationItemSelected(int position, long id) {
    // When the given dropdown item is selected, show its contents in the
    // container view.

    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.setCustomAnimations(R.anim.fade_in, R.anim.fade_out);

    if (position == NAV_DAY || position == NAV_WEEK) {
        mTimeTableFragment/*  ww w  . j a  v  a2  s  .  c om*/
                .setDisplayType(position == NAV_DAY ? TimeTableLayout.TYPE_DAY : TimeTableLayout.TYPE_WEEK);

        if (mTimeTableFragment.isHidden()) {
            transaction.hide(mSubjectListFragment);
            transaction.show(mTimeTableFragment);
        }
    } else if (position == NAV_LIST) {
        if (mSubjectListFragment.isHidden()) {
            transaction.hide(mTimeTableFragment);
            transaction.show(mSubjectListFragment);
        }
    }

    transaction.commit();

    mSpinnerAdapter.setViewType(position);

    return true;
}

From source file:org.spinsuite.view.V_Preferences.java

@Override
public void onItemSelected(int p_Item_ID) {
    //   Instance if not exists
    T_Pref_Parent m_PreferencePane = m_PreferenceListFragment.getPrefAt(p_Item_ID);
    //   /*  w  w  w.  j  a v a2  s .c  om*/
    m_CurrentPreference = p_Item_ID;
    //   Transaction
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    //   
    if (findViewById(R.id.ll_pr_list_land) != null) {
        if (!m_IsDetailAdded) {
            transaction.add(R.id.ll_pr_pane, m_PreferencePane, DETAIL_FRAGMENT);
            m_IsDetailAdded = true;
        } else {
            transaction.replace(R.id.ll_pr_pane, m_PreferencePane, DETAIL_FRAGMENT);
        }
    } else {
        transaction.hide(m_PreferenceListFragment);
        if (m_PreferencePane.isHidden()) {
            transaction.show(m_PreferencePane);
        } else if (!m_PreferencePane.isAdded()) {
            transaction.add(R.id.ll_pr_list, m_PreferencePane, DETAIL_FRAGMENT);
        }
    }
    //   
    transaction.commit();
    //   Change SubTitle
    String subtitle = m_PreferenceListFragment.getPrefTitleAt(p_Item_ID);
    actionBar.setSubtitle(subtitle);
}

From source file:us.nineworlds.serenity.ui.browser.movie.MovieBrowserActivity.java

@Override
protected void createSideMenu() {
    setContentView(R.layout.activity_movie_browser);
    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    MovieVideoGalleryFragment videoGalleryFragment = (MovieVideoGalleryFragment) fragmentManager
            .findFragmentByTag("videoGallery_fragment");
    VideoGridFragment videoGridFragment = (VideoGridFragment) fragmentManager
            .findFragmentByTag("videoGrid_fragment");

    if (gridViewActive) {
        fragmentTransaction.hide(videoGalleryFragment);
        fragmentTransaction.show(videoGridFragment);
        fragmentTransaction.commit();// w  w w .j a  v a2 s  .  c o  m
    } else {
        fragmentTransaction.hide(videoGridFragment);
        fragmentTransaction.show(videoGalleryFragment);
        fragmentTransaction.commit();
    }

    View fanArt = findViewById(R.id.fanArt);
    fanArt.setBackgroundResource(R.drawable.movies);

    initMenuDrawerViews();

    drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.menudrawer_selector,
            R.string.drawer_open, R.string.drawer_closed) {
        @Override
        public void onDrawerOpened(View drawerView) {

            super.onDrawerOpened(drawerView);
            getSupportActionBar().setTitle(R.string.app_name);
            drawerList.requestFocusFromTouch();
        }

        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            getSupportActionBar().setTitle(R.string.app_name);
            View gallery = findViewById(R.id.moviePosterGallery);
            if (!isGridViewActive()) {
                gallery.requestFocusFromTouch();
            }
        }
    };

    drawerLayout.setDrawerListener(drawerToggle);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);

    populateMenuDrawer();
}

From source file:net.frontdo.funnylearn.ui.activity.MainActivity.java

private void switchMainFragment(BaseFragment fragment) {
    if (mCurFragment == fragment) {
        return;/*from  w  w w. j  ava2s. c  o m*/
    }

    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    if (fragment.isAdded()) {
        transaction.show(fragment);
    } else {
        transaction.add(R.id.main_content, fragment);
    }

    if (mCurFragment != null) {
        transaction.hide(mCurFragment);
    }

    transaction.commit();
    mCurFragment = fragment;

    // for updating the goods
    if (fragment instanceof GoodsFragment) {
        fragment.onResume();
    }
}