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


Java FragmentManager.getFragment方法代碼示例

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


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

示例1: onCreate

import android.support.v4.app.FragmentManager; //導入方法依賴的package包/類
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.context = getActivity();

    if (savedInstanceState != null) {
        FragmentManager manager = getChildFragmentManager();
        zhihuDailyFragment = (ZhihuDailyFragment) manager.getFragment(savedInstanceState, "zhihu");
        guokrFragment = (GuokrFragment) manager.getFragment(savedInstanceState, "guokr");
        doubanMomentFragment = (DoubanMomentFragment) manager.getFragment(savedInstanceState, "douban");
    } else {
        zhihuDailyFragment = ZhihuDailyFragment.newInstance();
        guokrFragment = GuokrFragment.newInstance();
        doubanMomentFragment = DoubanMomentFragment.newInstance();
    }

    zhihuDailyPresenter = new ZhihuDailyPresenter(context, zhihuDailyFragment);
    guokrPresenter = new GuokrPresenter(context, guokrFragment);
    doubanMomentPresenter = new DoubanMomentPresenter(context, doubanMomentFragment);

}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:MainFragment.java

示例2: restore

import android.support.v4.app.FragmentManager; //導入方法依賴的package包/類
public void restore(FragmentManager fragmentManager, Bundle fragments) {
    mFragments.clear();
    if (fragments != null) {
        Iterable<String> keys = fragments.keySet();
        for (String key : keys) {
            if (key.startsWith("f")) {
                int index = Integer.parseInt(key.substring(1));
                IMasterFragment f = (IMasterFragment) fragmentManager.getFragment(fragments, key);
                if (f != null) {
                    while (mFragments.size() <= index) {
                        mFragments.add(null);
                    }
                    f.setMenuVisibility(false);
                    mFragments.set(index, f);
                } else {
                    Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}
 
開發者ID:alphater,項目名稱:garras,代碼行數:22,代碼來源:Records.java

示例3: onCreate

import android.support.v4.app.FragmentManager; //導入方法依賴的package包/類
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null) {
        FragmentManager fm = getChildFragmentManager();
        mZhihuFragment = (ZhihuDailyFragment) fm.getFragment(savedInstanceState, ZhihuDailyFragment.class.getSimpleName());
        mDoubanFragment = (DoubanMomentFragment) fm.getFragment(savedInstanceState, DoubanMomentFragment.class.getSimpleName());
        mGuokrFragment = (GuokrHandpickFragment) fm.getFragment(savedInstanceState, GuokrHandpickFragment.class.getSimpleName());
    } else {
        mZhihuFragment = ZhihuDailyFragment.newInstance();
        mDoubanFragment = DoubanMomentFragment.newInstance();
        mGuokrFragment = GuokrHandpickFragment.newInstance();
    }

    new ZhihuDailyPresenter(mZhihuFragment, ZhihuDailyNewsRepository.getInstance(
            ZhihuDailyNewsLocalDataSource.getInstance(getContext()),
            ZhihuDailyNewsRemoteDataSource.getInstance()));

    new DoubanMomentPresenter(mDoubanFragment, DoubanMomentNewsRepository.getInstance(
            DoubanMomentNewsRemoteDataSource.getInstance(),
            DoubanMomentNewsLocalDataSource.getInstance(getContext())));

    new GuokrHandpickPresenter(mGuokrFragment, GuokrHandpickNewsRepository.getInstance(
            GuokrHandpickNewsRemoteDataSource.getInstance(),
            GuokrHandpickNewsLocalDataSource.getInstance(getContext())));
}
 
開發者ID:SpeedPromise,項目名稱:L-Assistant,代碼行數:27,代碼來源:TimelineFragment.java

示例4: onCreate

import android.support.v4.app.FragmentManager; //導入方法依賴的package包/類
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.context = getActivity();

    if (savedInstanceState != null) {
        FragmentManager manager = getChildFragmentManager();
        zhihuDailyFragment = (ZhihuDailyFragment) manager.getFragment(savedInstanceState, "zhihu");
        //guokrFragment = (GuokrFragment) manager.getFragment(savedInstanceState, "guokr");
        doubanMomentFragment = (DoubanMomentFragment) manager.getFragment(savedInstanceState, "douban");
    } else {
        zhihuDailyFragment = ZhihuDailyFragment.newInstance();
        //guokrFragment = GuokrFragment.newInstance();
        doubanMomentFragment = DoubanMomentFragment.newInstance();
    }

    zhihuDailyPresenter = new ZhihuDailyPresenter(context, zhihuDailyFragment);
    //guokrPresenter = new GuokrPresenter(context, guokrFragment);
    doubanMomentPresenter = new DoubanMomentPresenter(context, doubanMomentFragment);

}
 
開發者ID:makezhao,項目名稱:LianXiZhihu,代碼行數:23,代碼來源:MainFragment.java

示例5: onRestoreInstanceState

import android.support.v4.app.FragmentManager; //導入方法依賴的package包/類
@Override
public void onRestoreInstanceState(Bundle inState) {
    super.onRestoreInstanceState(inState);
    FragmentManager fm = getSupportFragmentManager();
    mBookmarkFragment = (BookmarkFragment) fm.getFragment(inState, BOOKMARK_FRAGMENT);
    mTagsFragment = (TagsFragment) fm.getFragment(inState, TAGS_FRAGMENT);
    setupBookmarkFragmentListener();
    setupTagFragmentListener();
}
 
開發者ID:theScrabi,項目名稱:OCBookmarks,代碼行數:10,代碼來源:MainActivity.java

示例6: initFragments

import android.support.v4.app.FragmentManager; //導入方法依賴的package包/類
private void initFragments(Bundle savedInstanceState) {
    FragmentManager fm = getChildFragmentManager();
    if (savedInstanceState == null) {
        mTimelineFragment = TimelineFragment.newInstance();
        mInfoFragment = InfoReadFragment.newInstance();
        mFavoritesFragment = FavoritesFragment.newInstance();
    } else {
        mTimelineFragment = (TimelineFragment) fm.getFragment(savedInstanceState, TimelineFragment.class.getSimpleName());
        mFavoritesFragment = (FavoritesFragment) fm.getFragment(savedInstanceState, FavoritesFragment.class.getSimpleName());
        mInfoFragment = (InfoReadFragment) fm.getFragment(savedInstanceState, InfoReadFragment.class.getSimpleName());
    }

    if (!mTimelineFragment.isAdded()) {
        fm.beginTransaction()
                .add(R.id.container, mTimelineFragment, TimelineFragment.class.getSimpleName())
                .commit();
    }

    if (!mFavoritesFragment.isAdded()) {
        fm.beginTransaction()
                .add(R.id.container, mFavoritesFragment, FavoritesFragment.class.getSimpleName())
                .commit();

    }

    if (!mInfoFragment.isAdded()) {
        fm.beginTransaction()
                .add(R.id.container, mInfoFragment, InfoReadFragment.class.getSimpleName())
                .commit();
    }
}
 
開發者ID:SpeedPromise,項目名稱:L-Assistant,代碼行數:32,代碼來源:ReadFragment.java

示例7: initFragments

import android.support.v4.app.FragmentManager; //導入方法依賴的package包/類
private void initFragments(Bundle saveInstanceState){
    FragmentManager fm = getSupportFragmentManager();
    if(saveInstanceState == null){
        mReadFragment = ReadFragment.newInstance();
        mWeatherFragment = WeatherFragment.newInstance();
        mPassFragment = PassFragment.newInstance();
        mScheduleFragment = ScheduleFragment.newInstance();
        mInfoFragment = InfoFragment.newInstance();
    }else{
        mReadFragment = (ReadFragment) fm.getFragment(saveInstanceState, ReadFragment.class.getSimpleName());
        mWeatherFragment = (WeatherFragment) fm.getFragment(saveInstanceState, WeatherFragment.class.getSimpleName());
        mPassFragment = (PassFragment) fm.getFragment(saveInstanceState, PassFragment.class.getSimpleName());
        mScheduleFragment = (ScheduleFragment) fm.getFragment(saveInstanceState, ScheduleFragment.class.getSimpleName());
        mInfoFragment = (InfoFragment) fm.getFragment(saveInstanceState, InfoFragment.class.getSimpleName());
    }

    if(!mReadFragment.isAdded()){
        fm.beginTransaction()
                .add(R.id.main_fragment, mReadFragment, ReadFragment.class.getSimpleName())
                .commit();
    }

    if(!mWeatherFragment.isAdded()){
        fm.beginTransaction()
                .add(R.id.main_fragment, mWeatherFragment, WeatherFragment.class.getSimpleName())
                .commit();
    }

    if(!mPassFragment.isAdded()){
        fm.beginTransaction()
                .add(R.id.main_fragment, mPassFragment, PassFragment.class.getSimpleName())
                .commit();
    }

    if(!mScheduleFragment.isAdded()){
        fm.beginTransaction()
                .add(R.id.main_fragment, mScheduleFragment, ScheduleFragment.class.getSimpleName())
                .commit();
    }

    if(!mInfoFragment.isAdded()){
        fm.beginTransaction()
                .add(R.id.main_fragment, mInfoFragment, InfoFragment.class.getSimpleName())
                .commit();
    }
}
 
開發者ID:SpeedPromise,項目名稱:L-Assistant,代碼行數:47,代碼來源:MainActivity.java


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