下面列出了android.support.v4.app.Fragment#getId ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private String getStateId() {
if (stateId != null) {
return stateId;
}
Fragment parentFragment = getParentFragment();
stateId = parentFragment.getTag();
if (stateId == null) {
int id = parentFragment.getId();
if (id > 0) {
stateId = Integer.toString(id);
}
}
if (stateId == null) {
throw new IllegalStateException("Fragment dose not have a valid id");
}
return stateId;
}
public void setFragment(boolean isVerifying) {
Fragment current = getCurrentFragment();
Fragment frag = statusFrag;
if (isVerifying) {
frag = validationFrag;
}
if (current == null || frag.getId() != current.getId()) {
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(container.getId(), frag);
transaction.commitAllowingStateLoss();
}
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
if (currTransaction == null) {
currTransaction = fm.beginTransaction();
}
Fragment fragment = getExistingFragment(position);
if (fragment != null) {
if (fragment.getId() == container.getId()) {
retentionStrategy.attach(fragment, currTransaction);
} else {
fm.beginTransaction().remove(fragment).commit();
fm.executePendingTransactions();
currTransaction.add(container.getId(), fragment,
getFragmentTag(position));
}
} else {
fragment = createFragment(entries.get(position).getDescriptor());
currTransaction.add(container.getId(), fragment,
getFragmentTag(position));
}
if (fragment != currPrimaryItem) {
fragment.setMenuVisibility(false);
fragment.setUserVisibleHint(false);
}
return fragment;
}
public void setFragment(boolean isVerifying) {
Fragment current = getCurrentFragment();
Fragment frag = statusFrag;
if (isVerifying) {
frag = validationFrag;
}
if (current == null || frag.getId() != current.getId()) {
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(container.getId(), frag);
transaction.commitAllowingStateLoss();
}
}
public static String getFragmentId(Fragment fragment) {
String index = getIndex(fragment);
int id = fragment.getId();
String tag = fragment.getTag();
if (tag == null) {
tag = "null";
}
return index + '/' + id + '/' + tag;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
if (currTransaction == null) {
currTransaction=fm.beginTransaction();
}
Fragment fragment=getExistingFragment(position);
if (fragment != null) {
if (fragment.getId() == container.getId()) {
retentionStrategy.attach(fragment, currTransaction);
}
else {
fm.beginTransaction().remove(fragment).commit();
fm.executePendingTransactions();
currTransaction.add(container.getId(), fragment,
getFragmentTag(position));
}
}
else {
fragment=createFragment(entries.get(position).getDescriptor());
currTransaction.add(container.getId(), fragment,
getFragmentTag(position));
}
if (fragment != currPrimaryItem) {
fragment.setMenuVisibility(false);
fragment.setUserVisibleHint(false);
}
return fragment;
}
@Override
public void onAttachFragment(Fragment fragment) {
super.onAttachFragment(fragment);
if (fragment.getId() == R.id.fragment_dlqueue) mDlQueueFragment = (DlQueueFragment) fragment;
}
@Override
public int getId(Fragment fragment) {
return fragment.getId();
}
@Override
public int getId(Fragment fragment) {
return fragment.getId();
}