I am using the following code to launch a new fragment from a FragmentActivity:
PlaceholderFragment placeholderFragment = new PlaceholderFragment();
String TAG="TestFragment";
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.fragment_container, newFrag, TAG);
ft.addToBackStack(TAG);
ft.commit();
The Placeholderfragment:
public class PlaceholderFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
return rootView;
}
}
For some reason, the "fragment_main" layout is not showing up.
I have debugged the flow and the etire code is executed but the screen stays at my FragmentActivity. Anyone has any idea why this might happen? I have already wasted an hour without any clue.
@Xaver Kapeller: You are right, it turned out the R.id.fragment_container was obscured by the parent linear_layout of the FragmentActivity as it had "fill_parent" specified.
Looks like my concepts of fragments are not very clear :P
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments