insert and remove fragments into viewpager properly

前端 未结 3 994
旧时难觅i
旧时难觅i 2021-02-03 12:02

I\'m making an adroid application with viewpager and fragments. I want to make an option to add or remove fragment pages to the pager dynamically. I have a custom FragmentPagerA

3条回答
  •  悲&欢浪女
    2021-02-03 12:29

    I can remove any fragment except the 0.

    For me it works if just use a >= condition whitin the removeItem's for-loop:

         if (i >= pos){
              fm.beginTransaction().remove(fragments.get(i).getFragment()).commit();
          }
    

提交回复
热议问题