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


Java Fragment.isDetached方法代碼示例

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


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

示例1: switchFragment

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
private void switchFragment(@NonNull Fragment fragment, String tag) {
    if (fragment.isAdded()) {
        return;
    }

    final FragmentManager manager = getSupportFragmentManager();
    final FragmentTransaction fragmentTransaction = manager.beginTransaction();

    final Fragment currentFragment = manager.findFragmentById(R.id.container);
    if (currentFragment != null) {
        fragmentTransaction.detach(currentFragment);
    }

    if (fragment.isDetached()) {
        fragmentTransaction.attach(fragment);
    } else {
        fragmentTransaction.add(R.id.container, fragment, tag);
    }
    fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
            .commit();
}
 
開發者ID:soramitsu,項目名稱:iroha-demo-android,代碼行數:22,代碼來源:MainActivity.java

示例2: getItemPosition

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@Override
public int getItemPosition(Object object) {
    if (object instanceof Fragment) {
        final Fragment fragment = (Fragment) object;
        final String tag = fragment.getTag();
        if (fragment.isDetached() || tag == null) {
            return POSITION_NONE;
        }

        int position = 0;
        for (T data : mList) {
            if (tag.equals(makeFragmentTag(mContainerId, getItemId(data)))) {
                return position;
            }
            position++;
        }

        return POSITION_NONE;
    }

    return super.getItemPosition(object);
}
 
開發者ID:nekocode,項目名稱:Hubs,代碼行數:23,代碼來源:ExFragmentPagerAdapter.java

示例3: showDirectoryWithSelectedTab

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
private void showDirectoryWithSelectedTab(FileInfo fileInfo) {
    Preconditions.checkNotNull(fileInfo, "fileInfo == null");
    Preconditions.checkNotNull(mSelectedDirectory, "mSelectedDirectory == null");
    Log.d(TAG, "showDirectoryWithSelectedTab: " + fileInfo.getName());
    if (mSelectedDirectory != fileInfo) {
        FragmentTransaction ft = mFragmentManager.beginTransaction();
        Fragment f = mFragmentManager.findFragmentByTag(mSelectedDirectory.getAbsolutePath());
        if (f != null && !f.isDetached()) {
            ft.detach(f);
        }

        mSelectedDirectory = fileInfo;

        f = mFragmentManager.findFragmentByTag(fileInfo.getAbsolutePath());
        if (f == null) {
            f = FileInfosFragment.newInstance(fileInfo.getAbsolutePath());
            ft.add(R.id.contentFrame, f, fileInfo.getAbsolutePath());
        } else {
            ft.attach(f);
        }
        ft.commit();
    }
}
 
開發者ID:JulianAndroid,項目名稱:AppChooser,代碼行數:24,代碼來源:FileInfosActivity.java

示例4: onBackPressed

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@Override
public void onBackPressed()
{
    if (mFragmentManager.findFragmentByTag("home").isDetached())
    {
        fragStuff.setFragmentByTag("home");
        for (Fragment fragment : mFragmentManager.getFragments())
        {
            if (fragment != null && !fragment.isDetached() && fragment instanceof ChatFragment)
            {
                if (((ChatFragment) fragment).getmSlidingMenu().isMenuShowing())
                {
                    ((ChatFragment) fragment).getmSlidingMenu().hideMenu(true);
                }
            }
        }
        if (mChatroomSlidingMenu.isMenuShowing())
        {
            mChatroomSlidingMenu.hideMenu(true);
        }
    }
    else if (mChatroomSlidingMenu.isMenuShowing())
    {
        mChatroomSlidingMenu.hideMenu(true);
    }
    else
    {
        super.onBackPressed();
    }
}
 
開發者ID:HueToYou,項目名稱:ChatExchange-old,代碼行數:31,代碼來源:MainActivity.java

示例5: reattachRemovedFragment

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
private void reattachRemovedFragment(Fragment fragment, FragmentTransaction fragmentTransaction, Path key, int containerId) {
    if(fragment == null) {
        fragment = key.createFragment();
    }
    if(!fragment.isAdded() || (fragment.isDetached() || fragment.getView() == null)) {
        fragmentTransaction.add(containerId, fragment, key.getFragmentTag());
    }
}
 
開發者ID:Zhuinden,項目名稱:simple-stack,代碼行數:9,代碼來源:MasterDetailFragmentStateChanger.java

示例6: removeToDetachFragment

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
private Fragment removeToDetachFragment(StateChange stateChange, Path key) {
    Fragment fragment = fragmentManager.findFragmentByTag(key.getFragmentTag());
    if(fragment != null && (fragment.isDetached() || fragment.getView() == null)) {
        FragmentTransaction fragmentTransaction = beginFragmentTransaction(stateChange);
        Fragment.SavedState savedState = fragmentManager.saveFragmentInstanceState(fragment);
        fragmentTransaction.remove(fragment);
        fragmentTransaction.commitNow();
        fragment.setInitialSavedState(savedState);
    }
    return fragment;
}
 
開發者ID:Zhuinden,項目名稱:simple-stack,代碼行數:12,代碼來源:MasterDetailFragmentStateChanger.java

示例7: showDirectoryWithBackPressed

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
private void showDirectoryWithBackPressed() {
    Preconditions.checkNotNull(mSelectedDirectory, "mSelectedDirectory == null");
    Preconditions.checkArgument(mDirectories.contains(mSelectedDirectory),
            "mDirectories not contain:" + mSelectedDirectory.getAbsolutePath());
    final int selectedPosition = mDirectories.indexOf(mSelectedDirectory);
    if (selectedPosition == 0) {
        finish();
    } else {
        FragmentTransaction ft = mFragmentManager.beginTransaction();
        Fragment f = mFragmentManager.findFragmentByTag(mSelectedDirectory.getAbsolutePath());
        if (f != null && !f.isDetached()) {
            ft.detach(f);
        }
        int previousPosition = selectedPosition - 1;
        FileInfo previous = mSelectedDirectory = mDirectories.get(previousPosition);
        f = mFragmentManager.findFragmentByTag(previous.getAbsolutePath());
        if (f == null) {
            f = FileInfosFragment.newInstance(previous.getAbsolutePath());
            ft.add(R.id.contentFrame, f, previous.getAbsolutePath());
        } else {
            ft.attach(f);
        }
        ft.commit();

        Message msg = mMyHandler.obtainMessage();
        msg.arg1 = previousPosition;
        mMyHandler.sendMessageDelayed(msg, 100L);
    }
}
 
開發者ID:JulianAndroid,項目名稱:AppChooser,代碼行數:30,代碼來源:FileInfosActivity.java

示例8: showChart

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
private void showChart() {
    Fragment fragment = getSupportFragmentManager().findFragmentByTag(CHART_FRAGMENT);
    if (fragment != null && !fragment.isDetached() && fragment.getId() != R.id.chart_dual) {
        return;
    }
    openSinglePaneChartFragment();
}
 
開發者ID:rjaros87,項目名稱:pm-home-station,代碼行數:8,代碼來源:MainActivity.java

示例9: setFragmentByTag

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
/**
 * Open a chat using its tag
 *
 * @param tag the chat's fragment tag (should be its URL)
 */

public void setFragmentByTag(String tag)
{
    Log.e("TAG", tag);
    if (mainActivity.mFragmentManager.getFragments() != null)
    {
        for (Fragment fragment : mainActivity.mFragmentManager.getFragments())
        {
            if (fragment != null && !fragment.isDetached())
            {
                mainActivity.mFragmentManager.beginTransaction().detach(fragment).commit();
            }
        }
        Fragment fragToAttach = mainActivity.mFragmentManager.findFragmentByTag(tag);

        if (fragToAttach != null)
        {

            if (tag.equals("home"))
            {
                mainActivity.mFragmentManager.beginTransaction().setCustomAnimations(R.anim.fade_in, R.anim.fade_out).attach(fragToAttach).commit();
                mainActivity.mCurrentUsers_SlidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
                ((HomeFragment) fragToAttach).hueTest();
            }
            else
            {
                if (mainActivity.mFragmentManager.findFragmentByTag("home").isDetached())
                {
                    mainActivity.mFragmentManager.beginTransaction().attach(fragToAttach).commit();
                }
                else
                {
                    mainActivity.mFragmentManager.beginTransaction().setCustomAnimations(R.anim.fade_in, R.anim.fade_out).attach(fragToAttach).commit();
                }
                mainActivity.mCurrentUsers_SlidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
            }
        }
        else
        {
            Log.e("TAG", tag);
        }

    }
}
 
開發者ID:HueToYou,項目名稱:ChatExchange-old,代碼行數:50,代碼來源:FragStuff.java


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