本文整理汇总了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);
}
示例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);
}
}
}
}
}
示例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())));
}
示例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);
}
示例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();
}
示例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();
}
}
示例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();
}
}