當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。