我有一个活动,该活动具有一个视图寻呼机,而在Fragment中,我有一个制表符布局,并将该片段放在没有视图寻呼机的制表符布局中。将片段绑定到viewpager并滑动时会更改活动,但不会改变布局中的片段,显示为空。
fc -P
这是适配器
tabLayout = view.findViewById(R.id.productdetail_tab);
replaceFragment(new ProductDetails());
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
switch(tab.getPosition()){
case 0:
replaceFragment(new ProductDetails());
break;
case 1:
replaceFragment(new RelatedProducts());
break;
}
}
});
public void replaceFragment(Fragment fragment){
FragmentManager fm = getActivity().getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.container, fragment);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.commit();
}