public class MyFragment2 extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_myfragment2, container, false);
return rootView;
}
}
public class MyFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_myfragment, container, false);
return rootView;
}
}
setContentView(R.layout.activity_main);
if(CONDITION == true)
MyFragment fragment = new MyFragment();
else
MyFragment2 fragment = new MyFragment2();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.fragment_placeholder, fragment);
ft.commit();