Michael Seltenreich
Michael Seltenreich

Reputation: 3488

Adding fragments to a fragment

I am very new to Android (been at it for 1 week), and I can't seem to find the answer to what I am after.

I have in my main activity 3 tabs:

When clicking each tab, I effectively load a fragment (corresponding to each one of my tabs) into my Main activity layout.

Additionally I have a fragment called articleEntryFragment.

For every one of my tab fragments I would like to load multiple article entries.

But as I understand it. Nested fragments don't work on APIs earlier than 17, and I want to have as much backward compatibility as possible.

Therefore, how is this very basic principal achieved?

For instance, when you go on the YouTube app, there are tabs, each tab has different videos.

It's my assumption that like in my app. Every tab is its own fragment, and every video listing uses a similar concept to my articleEntry fragment.

What's the proper way to achieve what I am after?

Thank you.

p.s. not looking for anyone to write code for me, but rather, direct me in the right path.

Upvotes: 2

Views: 76

Answers (4)

Duan Bressan
Duan Bressan

Reputation: 625

Excellent question.

This doubt is very common.

In the documentation have everything you need, look at this:

Nested Fragments And Fragment Pager Adapter And Fragment

For your answer, I understand that I wanted to do something like this:

enter image description here

There are two libraries in github with can help you:

Pager Sliding Tab Strip

Material Tabs

Review and use these examples that will be very useful.

I found these links here, if you want to take a look, there are other different libraries that can help you.

I hope it helps.

Upvotes: 2

Cheticamp
Cheticamp

Reputation: 62831

Although nested fragments were introduced in API 17, they are available in the support library down to Android version 1.6. See "Nested Fragment" here.

The Android Support Library also now supports nested fragments, so you can implement nested fragment designs on Android 1.6 and higher.

You will need to include the support library in your build to use nested fragments.

Hope that helps.

Upvotes: 0

ianhanniballake
ianhanniballake

Reputation: 199805

Nested fragments are supported in the Support Library Fragments and provide support back to API 7 (as of version 25.3.1)

Upvotes: 0

Larry Schiefer
Larry Schiefer

Reputation: 15775

Use android.support.v4.app.Fragment and android.support.v13.app.FragmentCompat.

Upvotes: 0

Related Questions