user863873
user863873

Reputation:

Removing all fragments with same tag

I open new fragments with this :

fragment = new Frag_Business_Dialog();  
fragment.setArguments(bundle); 
FragmentManager fragmentManager = getFragmentManager();  
fragmentManager.beginTransaction().setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE).add(R.id.mainContent, fragment,"mesaj_chat").commit();

and i remove them by this on button press:

  getFragmentManager().beginTransaction().remove(getFragmentManager().findFragmentByTag("mesaj_chat")).commit();

My app can open one or two... or many same fragments. And i want to remove all of them with the same tag by one line of code ( one press of a button ). With the code above i remove one by one. How can i tag all this fragments and remove them at once?

Thanks!

Upvotes: 2

Views: 1069

Answers (1)

JDenais
JDenais

Reputation: 3016

I've not tried it but I'd say keep the count of how many fragments you have and then loop on this count to remove all the fragments one by one.

Upvotes: 1

Related Questions