android - How to replace fragment properly using navigation drawer -


i using navigation drawer , simple use. not providing complete code providing detail easy understand problem. using fragments these 8 in numbers , replacing them 1 other. here comes problem replacing them on click event of navigation drawer. there 2 main problems

  1. after replacement , can see previous fragment in background. replace method call new fragment on ? if yes should old fragment not visible in background of new fragment.

  2. when click navigation drawer item , loads specific fragment successfully. keeping in fragment when click specific item again loads fragment again , again. example if drawer item num 3 opens fragment mybook , clicking item num 3 2 or many times open fragment time.

so please 1 answer me how cure app such kind of actions described above.

i tried this. working fine me

    fragmentmanager frgmanager = getfragmentmanager();     frgmanager.popbackstack(null, fragmentmanager.pop_back_stack_inclusive);     fragmenttransaction frgtransaction = frgmanager.begintransaction();      if(subitem.equalsignorecase("subitem")){         frag1 frg1 =new frag1(mctx);         frgtransaction.replace(r.id.inflate_layout, frg1);     }else if(subitem1.equalsignorecase("subitem1")){         frag2 frg2 =new frag2(mctx);         frgtransaction.replace(r.id.inflate_layout, frg2);     }else{         frag2 frg3 =new frag3(mctx);         frgtransaction.replace(r.id.inflate_layout, frg3);     }     frgtransaction.settransition(fragmenttransaction.transit_fragment_fade);     frgtransaction.commit(); 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -