android - Hide fragments upon button click -


i have 3 buttons , 1 frame layout works container 3 different fragments in layout.

when click button a, fragment opens, , on clicking button b fragment b replaces fragment a. same c.

so question - suppose if user clicks button , fragment opens, , if clicks button again fragment open. fragment should gone. code looks similar

onclicklistener listener = new onclicklistener() {     public void onclick(view view) {         fragment fragment = null;         if(view == findviewbyid(r.id.button1)){             fragment = new fragmentone();         } else {             fragment = new fragmenttwo();                            }         fragmentmanager manager = getsupportfragmentmanager();         fragmenttransaction transaction = manager.begintransaction();         transaction.replace(r.id.output, fragment);         transaction.commit();     } };  button btn1 = (button)findviewbyid(r.id.button1); btn1.setonclicklistener(listener); button btn2 = (button)findviewbyid(r.id.button2); btn2.setonclicklistener(listener); 

now want know should write in code disappear fragment.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -