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


Java FragmentTag类代码示例

本文整理汇总了Java中android.support.v4.app.FragmentActivity.FragmentTag的典型用法代码示例。如果您正苦于以下问题:Java FragmentTag类的具体用法?Java FragmentTag怎么用?Java FragmentTag使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FragmentTag类属于android.support.v4.app.FragmentActivity包,在下文中一共展示了FragmentTag类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: inflate

import android.support.v4.app.FragmentActivity.FragmentTag; //导入依赖的package包/类
private static View inflate(AttributeSet attrs, View parent, FragmentActivity activity,
                            Fragment parentFragment) {
    String fname = attrs.getAttributeValue(null, "class");
    TypedArray a = activity.obtainStyledAttributes(attrs, FragmentTag.Fragment);
    if (fname == null) {
        fname = a.getString(FragmentTag.Fragment_name);
    }
    if (fname.startsWith(".")) {
        fname = activity.getPackageName() + fname;
    }
    int id = a.getResourceId(FragmentTag.Fragment_id, View.NO_ID);
    String tag = a.getString(FragmentTag.Fragment_tag);
    a.recycle();
    int containerId = parent != null ? parent.getId() : View.NO_ID;
    if (containerId == View.NO_ID && id == View.NO_ID && tag == null) {
        throw new IllegalArgumentException(
                attrs.getPositionDescription()
                        + ": Must specify unique android:id, android:tag, or have a parent with an id for "
                        + fname);
    }
    FragmentManagerImpl impl = obtainFragmentManager(activity, parentFragment);
    Fragment fragment = id != View.NO_ID ? impl.findFragmentById(id) : null;
    if (fragment == null && tag != null) {
        fragment = impl.findFragmentByTag(tag);
    }
    if (fragment == null && containerId != View.NO_ID) {
        fragment = impl.findFragmentById(containerId);
    }
    if (fragment == null) {
        fragment = Fragment.instantiate(activity, fname);
        fragment.mParentFragment = parentFragment;
        fragment.mActivity = activity;
        fragment.mFromLayout = true;
        fragment.mFragmentId = id != 0 ? id : containerId;
        fragment.mContainer = (ViewGroup) parent;
        fragment.mContainerId = containerId;
        fragment.mTag = tag;
        fragment.mInLayout = true;
        fragment.mFragmentManager = impl;
        fragment.onInflate(activity, attrs, fragment.mSavedFragmentState);
        impl.addFragment(fragment, true);
    } else if (fragment.mInLayout) {
        throw new IllegalArgumentException(attrs.getPositionDescription()
                + ": Duplicate id 0x" + Integer.toHexString(id)
                + ", tag " + tag + ", or parent id 0x" + Integer.toHexString(containerId)
                + " with another fragment for " + fname);
    } else {
        fragment.mInLayout = true;
        if (!fragment.mRetaining) {
            fragment.onInflate(activity, attrs, fragment.mSavedFragmentState);
        }
        impl.moveToState(fragment);
    }
    if (fragment.mView == null) {
        throw new IllegalStateException("Fragment " + fname
                + " did not create a view.");
    }
    if (id != 0) {
        fragment.mView.setId(id);
    }
    if (fragment.mView.getTag() == null) {
        fragment.mView.setTag(tag);
    }
    return fragment.mView;
}
 
开发者ID:restorer,项目名称:gloomy-dungeons-2,代码行数:66,代码来源:_HoloFragmentInflater.java

示例2: inflate

import android.support.v4.app.FragmentActivity.FragmentTag; //导入依赖的package包/类
private static View inflate(AttributeSet attrs, View parent, FragmentActivity activity,
        Fragment parentFragment) {
    String fname = attrs.getAttributeValue(null, "class");
    TypedArray a = activity.obtainStyledAttributes(attrs, FragmentTag.Fragment);
    if (fname == null) {
        fname = a.getString(FragmentTag.Fragment_name);
    }
    if (fname.startsWith(".")) {
        fname = activity.getPackageName() + fname;
    }
    int id = a.getResourceId(FragmentTag.Fragment_id, View.NO_ID);
    String tag = a.getString(FragmentTag.Fragment_tag);
    a.recycle();
    int containerId = parent != null ? parent.getId() : 0;
    if (containerId == View.NO_ID && id == View.NO_ID && tag == null) {
        throw new IllegalArgumentException(
                attrs.getPositionDescription()
                        + ": Must specify unique android:id, android:tag, or have a parent with an id for "
                        + fname);
    }
    FragmentManagerImpl impl = obtainFragmentManager(activity, parentFragment);
    Fragment fragment = id != View.NO_ID ? impl.findFragmentById(id) : null;
    if (fragment == null && tag != null) {
        fragment = impl.findFragmentByTag(tag);
    }
    if (fragment == null && containerId != View.NO_ID) {
        fragment = impl.findFragmentById(containerId);
    }
    if (fragment == null) {
        fragment = Fragment.instantiate(activity, fname);
        fragment.mParentFragment = parentFragment;
        fragment.mActivity = activity;
        fragment.mFromLayout = true;
        fragment.mFragmentId = id != 0 ? id : containerId;
        fragment.mContainer = (ViewGroup) parent;
        fragment.mContainerId = containerId;
        fragment.mTag = tag;
        fragment.mInLayout = true;
        fragment.mFragmentManager = impl;
        fragment.onInflate(activity, attrs, fragment.mSavedFragmentState);
        impl.addFragment(fragment, true);
    } else if (fragment.mInLayout) {
        throw new IllegalArgumentException(attrs.getPositionDescription()
                + ": Duplicate id 0x" + Integer.toHexString(id)
                + ", tag " + tag + ", or parent id 0x" + Integer.toHexString(containerId)
                + " with another fragment for " + fname);
    } else {
        fragment.mInLayout = true;
        if (!fragment.mRetaining) {
            fragment.onInflate(activity, attrs, fragment.mSavedFragmentState);
        }
        impl.moveToState(fragment);
    }
    if (fragment.mView == null) {
        throw new IllegalStateException("Fragment " + fname
                + " did not create a view.");
    }
    if (id != 0) {
        fragment.mView.setId(id);
    }
    if (fragment.mView.getTag() == null) {
        fragment.mView.setTag(tag);
    }
    return fragment.mView;
}
 
开发者ID:WassimBenltaief,项目名称:laposte-android,代码行数:66,代码来源:_HoloFragmentInflater.java


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