조각 점프

getSupportFragment Manager()를 사용 합 니 다.findFragment ByTag(tag)를 찾 을 수 없습니다.비어 있 습 니 다.replace()를 사용 할 때 fragment 를 스 택 에 넣 어야 하기 때 문 입 니 다.다음 방법 을 호출 할 것 을 보증 합 니 다:ft.addToBackStack(tag);
/** * Example of starting nested fragment from another fragment: Fragment * newFragment = ManagerTagFragment.newInstance(tag.getMac()); TagsActivity * tAct = (TagsActivity)getActivity(); tAct.pushFragments(newFragment, true, * true, null); * -------------------------------------------------------------- * fragement   * * @param fragment *        * @param shouldAnimate *        * @param addToBackStack *          (             *      getSupportFragmentManager().findFragmentByTag * (setting))       (        ,         ) * @param tag *      */
public void pushFragments(Fragment fragment, boolean shouldAnimate,
boolean addToBackStack, String tag) {
FragmentManager manager = getSupportFragmentManager();// getFragmentManager();
FragmentTransaction ft = manager.beginTransaction();
if (shouldAnimate) {
// ft.setCustomAnimations(R.animator.fragment_slide_left_enter,
// R.animator.fragment_slide_left_exit,
// R.animator.fragment_slide_right_enter,
// R.animator.fragment_slide_right_exit);
}
ft.replace(R.id.sdk_main_content, fragment, tag);
// ft.attach(fragment);


if (addToBackStack) {
/* * here you can create named backstack for realize another logic. * ft.addToBackStack("name of your backstack"); */
ft.addToBackStack(tag);
} else {
/* * and remove named backstack: * manager.popBackStack("name of your backstack", * FragmentManager.POP_BACK_STACK_INCLUSIVE); or remove whole: * manager.popBackStack(null, * FragmentManager.POP_BACK_STACK_INCLUSIVE); */
manager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
}
ft.commit();
}

좋은 웹페이지 즐겨찾기