当前位置: 首页>>代码示例>>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;未经允许,请勿转载。