BabakHSL
BabakHSL

Reputation: 772

How to programmatically add two Fragments to a layout?

i have trouble with attaching two fragments in one layout. I know how to add one fragment in a layout but I don't know how to put two fragments next to each other vertically in java android. here adding one fragment is fully explained but there is no tutorial for putting two or more fragments in one layout.

Upvotes: 0

Views: 1538

Answers (2)

Illegal Argument
Illegal Argument

Reputation: 10338

You can try something like this:

FragmentTransaction ft = getFragmentManager()
                    .beginTransaction();
Fragment fragment = new MyAwsomeFragment();
            ft.add(R.id.linearLayoutActivity, fragment, null);//dont add to backstack
            ft.commit();

Here R.id.linearLayoutActivity points to a layout currently visible and inflated by the activity.

Upvotes: 0

Rohit5k2
Rohit5k2

Reputation: 18112

Create two FrameLayout in your xml file and place them the way you want. Add fragment in each of them.

Or see this link for nested fragments

Upvotes: 2

Related Questions