我正在使用fragmentTransaction来处理片段,它看起来像这样:
FragmentManager fm = oldFragment.getFragmentManager(); FragmentTransaction fragmentTransaction = fm.beginTransaction(); fragmentTransaction.add(oldFragment.getId(),newFragment,tag); fragmentTransaction.hide(oldFragment); fragmentTransaction.addToBackStack(tag); fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); fragmentTransaction.commit();
有几个片段我想在回去时跳过其中的一些片段.
例:
Frag1 -> (Press Next) -> Frag2 -> (Press Next) -> Frag3 -> (Press Back) -> Frag1
getFragmentManager().popBackStack( tag,FragmentManager.POP_BACK_STACK_INCLUSIVE);
解决方法
我使用此功能删除碎片告诉我,如果我帮助.
public static void removeFragment(FragmentActivity activity) { try { FragmentManager supportFragmentManager = activity.getSupportFragmentManager(); // getFragmentManager(); FragmentTransaction fragmentTransaction = supportFragmentManager.beginTransaction(); fragmentTransaction.setCustomAnimations(R.anim.slide_down,R.anim.slide_up); fragmentTransaction.remove(supportFragmentManager.getFragments().get(0)); try { fragmentTransaction.commit(); } catch (Exception e) { } supportFragmentManager.popBackStack(); } catch (NullPointerException exception) { exception.printstacktrace(); } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。