Android switch Fragments in the new design support navigation drawer -
how can switch fragments in new design support navigation drawer? found example codes on cheesesquare github on how switch fragments using tablayout, not navigation drawer. same? not recreate fragments when switching, rather tablayout retains fragments instance , fragment`s content how user left it.
write code this:
navigationview.setnavigationitemselectedlistener( new navigationview.onnavigationitemselectedlistener() { @override public boolean onnavigationitemselected(menuitem menuitem) { menuitem.setchecked(true); mdrawerlayout.closedrawers(); switch (menuitem.getitemid()) { case r.id.your_menu_id: getsupportfragmentmanager().begintransaction().replace(r.id.fragment, getfragment(), "set_a_tag").addtobackstack("set_a_tag").commit(); break; } return true; } }); private yourfragment getfragment() { yourfragment f = getsupportfragmentmanager().findfragmentbytag("set_a_tag"); if (f == null) { f = new yourfragment(); } return f; }
Comments
Post a Comment