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