I am using a LinearLayout with a vertical orientation to list fragments. I add fragments to the container programmatically like this:
FragmentTransaction ft = fragmentManager.beginTransaction();
Fragment fragment1 = new Fragment();
ft.add(R.id.llContainer, fragment1);
Fragment fragment2 = new Fragment();
ft.add(R.id.llContainer, fragment2);
ft.commit();
But it only shows the first fragment. Why?
Had the same problem, but using
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.control_list, container, false);
I.E. using a xml layout file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/control_list">
</LinearLayout>
Solved my problem. When creating the LinearList programmatically only the first fragment showed up for me too.
That is using an xml file for the layout you want to add the fragments to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With