Android FragmentPagerAdapter can't change tag of fragment -


i developing simple web beowser dynamic tabs allow user add/remove them. use fragmentpageradapter, viewpager , tablayout this. if create 2 tabs (add 2 fragments list) , remove second one, work , can add fragment list. if add 2 , remove firs 1 , try add new fragment list, recieve exception:

java.lang.illegalstateexception: can't change tag of fragment page{162e3786 #1 id=0x7f0d007d android:switcher:2131558525:1}: android:switcher:2131558525:1 android:switcher:2131558525:0 

i think thats because each fragment has unique id inside fragmentpageradapter. 2 fragments have id's 0 , 1. if remove first item(id 0) , add new one(id 1). item id 1 exists! there way change id's programmatically or set id's when creating fragments? in advance!

my fragmentpageradapter:

public class pageradapter extends fragmentpageradapter {      private list<page> fragments;      public pageradapter(fragmentmanager fm, list<page> pages) {         super(fm);         this.fragments = pages;     }      @override     public fragment getitem(int position) {         return this.fragments.get(position);     }      @override     public int getcount() {         return this.fragments.size();     }      @override     public int getitemposition(object object) {         int index = pages.indexof(object);         if (index == -1){             return pageradapter.position_none;         } else {             return index;         }     }      @override     public void destroyitem(viewgroup container, int position, object object) {         fragmentmanager manager = ((fragment) object).getfragmentmanager();         fragmenttransaction trans = manager.begintransaction();         trans.remove((fragment) object);         trans.commit();     } } 

finally, after hours of search , tries found solution. fix need override getitemid() method of fragmentpageradapter in have return unique id each fragment.


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -