如何在单个片段中使用多个片段?

时间:2019-05-19 07:05:51

标签: java android android-fragments

我想在一个片段中使用多个片段,我有一些有效的代码,但是当我通过BottomNavigationView更改Parent片段并再次返回该片段时,那里什么也没显示。

public class Home extends Fragment {

    SelectionPageAdapter selectionPageAdapter;
    ViewPager viewPager;
    TabLayout tabLayout;
    int mCurCheckPosition;

    public Home() {

    }


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View  view= inflater.inflate(R.layout.fragment_home, container, false);




        selectionPageAdapter=new SelectionPageAdapter(getFragmentManager());
        viewPager=view.findViewById(R.id.container);
        selectionPageAdapter.addFragment(new Feature_Item(),"Home");
        selectionPageAdapter.addFragment(new Best_Sellers(),"Best Sell");

        viewPager.setAdapter(selectionPageAdapter);
        tabLayout=view.findViewById(R.id.tabs);
        tabLayout.setupWithViewPager(viewPager);

        return view;
    }
}

0 个答案:

没有答案