How to solve for viewpager : The specified child already has a parent. You must call removeView() on the child's parent first

后端 未结 8 1589
半阙折子戏
半阙折子戏 2020-12-04 18:05

Into my project I am using viewpager with three tabs named History,Main,Map.Main activity contain Timer,stopwatch,etc

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-04 18:23

    if you are working with FragmentPagerAdapter then just use destroyItem method inside FragmentPagerAdapter.

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) 
    {
            FragmentTransaction ft=fm.beginTransaction();
            ft.remove((Fragment) object);
            ft.commit();
    }
    

    setOffscreenPageLimit(int limit) consumes more memory and in some cases its not works perfectly. its retain state in either side see description.setOffscreenPageLimit(int limit) - Set the number of pages that should be retained to either side of the current page in the view hierarchy in an idle state.

提交回复
热议问题