当前位置: 首页>>代码示例>>Java>>正文


Java Fragment.isAdded方法代码示例

本文整理汇总了Java中android.app.Fragment.isAdded方法的典型用法代码示例。如果您正苦于以下问题:Java Fragment.isAdded方法的具体用法?Java Fragment.isAdded怎么用?Java Fragment.isAdded使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.app.Fragment的用法示例。


在下文中一共展示了Fragment.isAdded方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onBackPressed

import android.app.Fragment; //导入方法依赖的package包/类
@Override
public void onBackPressed() {
    if (mDrawerLayout != null && mDrawerLayout.isDrawerOpen(Gravity.START)) {
        mDrawerLayout.closeDrawer(Gravity.START);
    } else {
        // TODO: To be improved:
        try {
            super.onBackPressed();
        } catch (IllegalStateException e){
            Fragment fragment = getFragmentManager().findFragmentByTag(MainFragment.class.getName());
            if (fragment == null) {
                fragment = new MainFragment();
            }
            if (!fragment.isAdded()) {
                FragmentTransaction transaction = getFragmentManager().beginTransaction();
                transaction.replace(R.id.content_frame, fragment, MainFragment.class.getName());
                transaction.commit();
            }
        }
    }
}
 
开发者ID:medialab-prado,项目名称:puremadrid,代码行数:22,代码来源:MainActivity.java

示例2: Overlay

import android.app.Fragment; //导入方法依赖的package包/类
/**
 * Must be created from the Fragment onViewCreated() method
 * @param fragment
 */
public Overlay(Fragment fragment) {

    if (!fragment.isAdded()) {
        throw new IllegalStateException("Overlay must be created once the fragment is added!");
    }

    mContext = fragment.getActivity();
    ViewGroup fragmentView = (ViewGroup)fragment.getView();
    if (fragmentView==null) {
        throw new IllegalStateException("Overlay must be created once the fragment has its view created!");
    }

    int parentViewId = -1;
    if (fragment instanceof BrowseFragment) {
        parentViewId = R.id.browse_frame;
    } else if (fragment instanceof MyVerticalGridFragment) {
        parentViewId = R.id.browse_dummy;
    } else if (fragment instanceof DetailsFragment) {
        parentViewId = R.id.details_fragment_root;
    } else if (fragment instanceof GuidedStepFragment) {
        parentViewId = R.id.guidedstep_background_view_root;
    } else {
        throw new IllegalStateException("Overlay is not compatible with this fragment: "+fragment);
    }

    ViewGroup parentView = (ViewGroup)fragmentView.findViewById(parentViewId);
    if (parentView==null) {
        throw new IllegalStateException("parentView not found! Maybe IDs in the leanback library have been changed?");
    }

    LayoutInflater.from(mContext).inflate(R.layout.leanback_overlay, parentView);
    mOverlayRoot = parentView.findViewById(R.id.overlay_root);
    mScanProgress = new ScannerAndScraperProgress(mContext, mOverlayRoot);
    mClock = new Clock(mContext, mOverlayRoot);
}
 
开发者ID:archos-sa,项目名称:aos-Video,代码行数:40,代码来源:Overlay.java

示例3: isFragmentAlive

import android.app.Fragment; //导入方法依赖的package包/类
public static boolean isFragmentAlive(Fragment fragment) {
    return fragment != null && fragment.isAdded();
}
 
开发者ID:myl2ning,项目名称:fragmentnav,代码行数:4,代码来源:Androids.java


注:本文中的android.app.Fragment.isAdded方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。