Android fragment show/hide is not working -


in activity have 2 fragments of same type different instances , want show 1 , hide other when different button pressed.

here code adding fragments activity:

_pardiscinemafragment = newslistingfragment.newinstance(tab_cinema);     _shoppingfragment = newslistingfragment.newinstance(tab_shopping);     fragmenttransaction transaction = getfragmentmanager().begintransaction();     transaction.setcustomanimations(             r.anim.enter_from_left,             r.anim.exit_to_left,             r.anim.enter_from_left,             r.anim.exit_to_left);     transaction.addtobackstack(null);     transaction.add(r.id.news_list_fragment_container, _pardiscinemafragment);     transaction.add(r.id.news_list_fragment_container, _shoppingfragment);     transaction.commit(); 

and here's onclick event:

public void ontabclick(view view) {       string tag = view.gettag().tostring();     fragment fragmenttoshow = null;     fragment fragmenttohide = null;     if(tag.equals(tab_cinema) && !currenttab.equals(tab_cinema)) {         currenttab = tab_cinema;         fragmenttoshow = _pardiscinemafragment;         fragmenttohide = _shoppingfragment;      }     else if(tag.equals(tab_shopping) && !currenttab.equals(tab_shopping)) {         currenttab = tab_shopping;         fragmenttoshow = _shoppingfragment;         fragmenttohide = _pardiscinemafragment;     }     if(fragmenttohide != null && fragmenttoshow != null) {         getfragmentmanager().begintransaction()           .setcustomanimations(android.r.animator.fade_in, android.r.animator.fade_out)           .hide(fragmenttohide)           .show(fragmenttoshow)           .commit();     } } 

but nothing happens , doesn't hide show fragments. because of way added? understand if 1 of fragments supposed hidden @ first, there no need add until user presses button since data has populated fragment view phone's database want happening @ while it's not visible.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -