Reputation: 314
I am making an Android app with Visual Studio and C#. I know I should porbably use Java, but I prefer C#, so I chose to use that. But anyway, I have a problem where I can't add the same fragment twice. I know this is a duplicate, but none of the other questions helped at all. Here is one I looked at:Adding multiple instances of the same fragment
All of my code is pretty much the same, except only one fragment gets added. Here is my code:
protected override void OnCreate(Bundle bundle) {
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
var trans = FragmentManager.BeginTransaction();
for(int i = 0; i < 5; i++)
trans.Add(Resource.Id.bottomLayout, new BottomFragment(), "Fragment_" + i.ToString());
trans.Commit();
}
Resource.Id.bottomLayout is a vertical LinearLayout, so I have no idea what the problem is. I feel like everyone will just get all mad because it's a duplicate(because that always happens to me, which is why I use this site as a last resort), but if I could receive some help, it would be appreciated.
Upvotes: 0
Views: 169
Reputation: 74104
I would assume that all five fragments are directly on top of each other.
Apply an android:orientation="vertical"
or android:orientation="vertical"
to your LinearLayout in order to get them to expand the LinearLayout
:
<LinearLayout
android:id="@+id/bottomLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
<LinearLayout
android:id="@+id/bottomLayout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal" />
Upvotes: 1