Previous fragment visible under the new fragment

后端 未结 7 1532
心在旅途
心在旅途 2021-02-05 04:10

I have a tab + ViewPager layout and in one of these tabs I have a list view. When I replace that list fragment upon the onclick I can still see the old fragment u

7条回答
  •  没有蜡笔的小新
    2021-02-05 04:30

    when need to remove all views from the parent view you need to call removeAllViews() at container in your onCreateView() method of your fragment.

    Here is the code:

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    
    container.removeAllViews(); // Inflate the layout for this fragment
     return inflater.inflate(R.layout.fragment_example, container, false); 
    }
    

提交回复
热议问题