當前位置: 首頁>>代碼示例>>Java>>正文


Java Fragment.isAdded方法代碼示例

本文整理匯總了Java中android.support.v4.app.Fragment.isAdded方法的典型用法代碼示例。如果您正苦於以下問題:Java Fragment.isAdded方法的具體用法?Java Fragment.isAdded怎麽用?Java Fragment.isAdded使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.v4.app.Fragment的用法示例。


在下文中一共展示了Fragment.isAdded方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: checkHide

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
/**
 * 切換fragment(隱藏)
 */
protected final void checkHide(int viewId, int showIndex) {
    List allFragment = bindFragment();
    hideAllFrag(showIndex);
    FragmentTransaction b = getSupportFragmentManager().beginTransaction();
    if (showIndex >= allFragment.size()) {
        Logger.e("showIndex >= allFragment.size():showIndex=" + showIndex + ",allFragment.size()=" + allFragment.size());
        return;
    }
    Fragment fragment = (Fragment) allFragment.get(showIndex);
    if (!fragment.isAdded()) {
        b.add(viewId, fragment);
    }
    b.show(fragment);
    b.commit();
}
 
開發者ID:zengcanxiang,項目名稱:MVP-Practice-Project-Template,代碼行數:19,代碼來源:FragmentActivity.java

示例2: switchFragment

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
/**
 * 轉換 Fragment
 * 首先當前存在 Fragment,並且當前 Fragment 不是要轉換的 Fragment ,避免重複操作
 * <p>
 * 被替換的 Fragment 隻是被覆蓋,並沒被銷毀
 *
 * @param fragment 需要轉換的Fargment
 */
public void switchFragment(Fragment fragment) {
    if (mCurrentFragment == null
            || !fragment.getClass().getName().equals(mCurrentFragment.getClass().getName())) {
        FragmentTransaction fragmentTransaction = mFragmentManager
                .beginTransaction()
                .setCustomAnimations(android.R.anim.fade_in,
                        android.R.anim.fade_out);
        if (!fragment.isAdded()) { // 檢查 fragment 是否被添加
            // 隱藏當前 mCurrentFragment,add fragment 到 Activity 中
            fragmentTransaction
                    .hide(mCurrentFragment)
                    .add(getFragmentContainerId(), fragment)
                    .commit();
            mCurrentFragment = fragment;
        } else {
            // 隱藏當前 mCurrentFragment,顯示 fragment
            fragmentTransaction
                    .hide(mCurrentFragment)
                    .show(fragment)
                    .commit();
            mCurrentFragment = fragment;
        }
    }
}
 
開發者ID:InnoFang,項目名稱:FamilyBond,代碼行數:33,代碼來源:FragmentContainerActivity.java

示例3: changeView

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
private void changeView(int position) {
    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    Fragment fragment = mFragments.get(position);
    if (fragment.isAdded()) {
        transaction.show(fragment);
    } else {
        transaction.add(R.id.sticky_container, fragment);
        mVisibleFragments.add(fragment);
    }
    for (Fragment fragment1 : mVisibleFragments) {
        if (fragment1 != fragment) {
            if (fragment1.isVisible()) {
                transaction.hide(fragment1);
                transaction.addToBackStack(null);
            }
        }
    }
    transaction.commit();
}
 
開發者ID:yedashen,項目名稱:UltimateRecyclerView,代碼行數:21,代碼來源:LikeStickListViewActivity.java

示例4: switchFragment

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
/**
 * 轉換Fragment
 * 首先當前存在Fragment,並且當前Fragment不是要轉換的Fragment,避免重複操作
 * @param fragment 需要轉換的Fargment
 */
public void switchFragment(Fragment fragment) {
    if (mCurrentFragment == null
            || !fragment.getClass().getName().equals(mCurrentFragment.getClass().getName())) {
        FragmentTransaction fragmentTransaction = mFragmentManager
                .beginTransaction()
                .setCustomAnimations(android.R.anim.fade_in,
                        android.R.anim.fade_out);
        if (!fragment.isAdded()) { // 檢查 fragment 是否被添加
            // 隱藏當前 mCurrentFragment,add fragment 到 Activity 中
            fragmentTransaction
                    .hide(mCurrentFragment)
                    .add(getFragmentContainerId(), fragment)
                    .commit();
            mCurrentFragment = fragment;
        } else {
            // 隱藏當前 mCurrentFragment,顯示 fragment
            fragmentTransaction
                    .hide(mCurrentFragment)
                    .show(fragment)
                    .commit();
            mCurrentFragment = fragment;
        }
    }
}
 
開發者ID:InnoFang,項目名稱:Android-Code-Demos,代碼行數:30,代碼來源:FragmentContainerActivity.java

示例5: switchFragment

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
/**
 * 轉換Fragment
 * 首先當前存在Fragment,並且當前Fragment不是要轉換的Fragment,避免重複操作
 *
 * @param fragment 需要轉換的Fargment
 */
public void switchFragment(Fragment fragment) {
    if (mCurrentFragment == null
            || !fragment.getClass().getName().equals(mCurrentFragment.getClass().getName())) {
        FragmentTransaction fragmentTransaction = mFragmentManager
                .beginTransaction()
                .setCustomAnimations(android.R.anim.fade_in,
                        android.R.anim.fade_out);
        if (!fragment.isAdded()) { // 檢查 fragment 是否被添加
            // 隱藏當前 mCurrentFragment,add fragment 到 Activity 中
            fragmentTransaction
                    .hide(mCurrentFragment)
                    .add(getFragmentContainerId(), fragment)
                    .commit();
            mCurrentFragment = fragment;
        } else {
            // 隱藏當前 mCurrentFragment,顯示 fragment
            fragmentTransaction
                    .hide(mCurrentFragment)
                    .show(fragment)
                    .commit();
            mCurrentFragment = fragment;
        }
    }
}
 
開發者ID:InnoFang,項目名稱:Android-Code-Demos,代碼行數:31,代碼來源:FragmentContainerActivity.java

示例6: showChildFragment

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
public void showChildFragment(@IdRes int id_content, Fragment fragment1, Fragment fragment2, Fragment fragment3) {
    FragmentTransaction ft = getChildFragmentManager().beginTransaction();
    if (!fragment1.isAdded()) {
        ft.add(id_content, fragment1);
    }
    if (!fragment2.isAdded()) {
        ft.add(id_content, fragment2);
    }
    if (!fragment3.isAdded()) {
        ft.add(id_content, fragment3);
    }
    ft.hide(fragment1);
    ft.hide(fragment2);
    ft.show(fragment3);
    ft.addToBackStack(null);
    ft.commit();
}
 
開發者ID:fengdongfei,項目名稱:CXJPadProject,代碼行數:18,代碼來源:BFragment.java

示例7: onCreateOptionsMenu

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.menu_main, menu);
    if (isPlaylistPage()) {
        menu.add(0, R.id.action_new_playlist, 0, R.string.new_playlist_title);
    }
    Fragment currentFragment = getCurrentFragment();
    if (currentFragment instanceof AbsLibraryPagerRecyclerViewCustomGridSizeFragment && currentFragment.isAdded()) {
        AbsLibraryPagerRecyclerViewCustomGridSizeFragment absLibraryRecyclerViewCustomGridSizeFragment = (AbsLibraryPagerRecyclerViewCustomGridSizeFragment) currentFragment;

        MenuItem gridSizeItem = menu.findItem(R.id.action_grid_size);
        if (Util.isLandscape(getResources())) {
            gridSizeItem.setTitle(R.string.action_grid_size_land);
        }
        setUpGridSizeMenu(absLibraryRecyclerViewCustomGridSizeFragment, gridSizeItem.getSubMenu());

        menu.findItem(R.id.action_colored_footers).setChecked(absLibraryRecyclerViewCustomGridSizeFragment.usePalette());
        menu.findItem(R.id.action_colored_footers).setEnabled(absLibraryRecyclerViewCustomGridSizeFragment.canUsePalette());
    } else {
        menu.add(0, R.id.action_new_playlist, 0, R.string.new_playlist_title);
        menu.removeItem(R.id.action_grid_size);
        menu.removeItem(R.id.action_colored_footers);
    }
    colorToolbar();
}
 
開發者ID:h4h13,項目名稱:RetroMusicPlayer,代碼行數:27,代碼來源:LibraryFragment.java

示例8: switchContent

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
/**
 * 動態加載fragment
 *
 * @param toFragment
 */
public void switchContent(Fragment toFragment) {
    if (mCurrentFrag != toFragment) {
        if (!toFragment.isAdded()) {
            if (mCurrentFrag != null) {
                mFragmentManager
                        .beginTransaction()
                        .hide(mCurrentFrag)
                        .commit();
            }
            mFragmentManager
                    .beginTransaction()
                    .add(R.id.main_view, toFragment)
                    .commit();
        }else {
            mFragmentManager.beginTransaction().hide(mCurrentFrag).show(toFragment).commit();
        }
        mCurrentFrag = toFragment;
    }

}
 
開發者ID:haihaio,項目名稱:AmenEye,代碼行數:26,代碼來源:MainActivity.java

示例9: onCreateOptionsMenu

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    if (pager == null) return;
    inflater.inflate(R.menu.menu_main, menu);
    if (isPlaylistPage()) {
        menu.add(0, R.id.action_new_playlist, 0, R.string.new_playlist_title);
    }
    Fragment currentFragment = getCurrentFragment();
    if (currentFragment instanceof AbsLibraryPagerRecyclerViewCustomGridSizeFragment && currentFragment.isAdded()) {
        AbsLibraryPagerRecyclerViewCustomGridSizeFragment absLibraryRecyclerViewCustomGridSizeFragment = (AbsLibraryPagerRecyclerViewCustomGridSizeFragment) currentFragment;

        menu.findItem(R.id.action_colored_footers).setChecked(absLibraryRecyclerViewCustomGridSizeFragment.usePalette());
        menu.findItem(R.id.action_colored_footers).setEnabled(absLibraryRecyclerViewCustomGridSizeFragment.canUsePalette());
    } else {
        menu.removeItem(R.id.action_colored_footers);
    }
    Activity activity = getActivity();
    if (activity == null) return;
    ToolbarContentTintHelper.handleOnCreateOptionsMenu(getActivity(), toolbar, menu, ATHToolbarActivity.getToolbarBackgroundColor(toolbar));
}
 
開發者ID:aliumujib,項目名稱:Orin,代碼行數:22,代碼來源:LibraryFragment.java

示例10: showFragment

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
private void showFragment(Fragment fragment, String tag, Fragment previousFragment) {
    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    if (previousFragment != null && !previousFragment.isHidden()) {
        fragmentTransaction.hide(previousFragment);
    }
    if (fragment.isHidden() || fragment.isAdded()) {
        fragmentTransaction.show(fragment);
    } else {
        fragmentTransaction.add(R.id.container, fragment, tag);
    }
    fragmentTransaction.commit();
}
 
開發者ID:mosquitolabs,項目名稱:referendum_1o_android,代碼行數:14,代碼來源:MainActivity.java

示例11: gotoHello

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
private void gotoHello() {
    Fragment f = fm.findFragmentByTag(HelloFragment.TAG);
    if (f == null) {
        f = HelloFragment.newInstance();
    }
    if (!f.isAdded()) {
        fm.beginTransaction().replace(R.id.main_container, f, HelloFragment.TAG).commit();
    }
}
 
開發者ID:wongcain,項目名稱:okuki,代碼行數:10,代碼來源:MainActivity.java

示例12: setPrimaryItem

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@Override
public void setPrimaryItem(ViewGroup container, int position, Object object) {
  super.setPrimaryItem(container, position, object);
  if (position != mLastPosition) {
    if (mLastPosition >= 0) {
      GlideApp.with(mLastFragment).pauseRequests();
    }
    Fragment current = (Fragment) object;
    mLastPosition = position;
    mLastFragment = current;
    if (current.isAdded()) {
      GlideApp.with(current).resumeRequests();
    }
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:16,代碼來源:FlickrSearchActivity.java

示例13: switchFragment

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
private void switchFragment(int from, int to) {
    this.mCurrentId = to;
    Fragment fromFragment = mFragments.get(from);
    Fragment toFragment = mFragments.get(to);
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    if (!toFragment.isAdded()) {
        ft.add(R.id.fl_fragment_container, toFragment).hide(fromFragment).commitAllowingStateLoss();
    } else {
        ft.show(toFragment).hide(fromFragment).commitAllowingStateLoss();
    }
}
 
開發者ID:iPanelkegy,項目名稱:MobileMedia,代碼行數:12,代碼來源:MainActivity.java

示例14: onCheckedChanged

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@Override
public void onCheckedChanged(RadioGroup radioGroup, int checkId) {
    for (int i = 0; i < radioGroup.getChildCount(); i++) {
        if (radioGroup.getChildAt(i).getId() == checkId) {
            //  即將要展示的Fragment
            Fragment target = mFragmentList.get(i);
            Fragment currentFragment = getCurrentFragment();
            currentFragment.onPause();

            FragmentTransaction fragmentTransaction = getFragmentTransaction();
            if (target.isAdded()) {
                target.onResume();
                fragmentTransaction.show(target).hide(currentFragment);

            } else {
                fragmentTransaction.add(mContentId, target).show(target).hide(currentFragment);
            }
            fragmentTransaction.commit();
            currentTab = i;

            if (mFragmentToogleListener != null) {
                mFragmentToogleListener.onToogleChange(target, currentTab);
            }

        }
    }

}
 
開發者ID:zuoni1018,項目名稱:CoordinatorLayoutExample-master,代碼行數:29,代碼來源:ZhiHuAdapter.java

示例15: showProgress

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
public static void showProgress(@NonNull final Fragment fragment, final SwipeRefreshLayout swipeRefreshLayout, boolean show) {
    if (!fragment.isAdded() || swipeRefreshLayout == null) return;

    if (!show) {
        swipeRefreshLayout.setRefreshing(false);
        return;
    }

    if (fragment.isResumed()) {
        swipeRefreshLayout.setRefreshing(true);
    } else {
        swipeRefreshLayout.post(() -> swipeRefreshLayout.setRefreshing(true));
    }
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:15,代碼來源:ViewUtils.java


注:本文中的android.support.v4.app.Fragment.isAdded方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。