Reputation: 25
I play arround with the SlidingTabsColors example from the android developers site. Where can I add a different content fragment? Now all tabs have the same fragment/layout. I tried to copy all important for the content fragment and renamed it, changed the fragment and the layout. But it dont works this way. Probably the ArrayList is not the best for different content?
Upvotes: 0
Views: 836
Reputation: 26
I am not sure whether I got the question right but the fact is that there are fragments created in
SlidingTabsColorsFragment.java
by the following method:
Fragment createFragment() {
return ContentFragment.newInstance(mTitle, mIndicatorColor, mDividerColor);
}
So I would suggest to simply change that method to something like this:
Fragment createFragment() {
return MyVeryOwnFragment.newInstance(mTitle, mIndicatorColor, mDividerColor);
}
Because there can only be Fragments displayed whose were created beforehand in this method. Then your own Fragment will be displayed in the content area.
You may also want to watch this video on the topic by the android developers youtube channel.
-------- Edit --------
Ok so the question was how to insert multiple different fragments:
Fragment createFragment() {
// Decide based on a class member which Fragment should be created.
Fragment frament;
if (mIndicatorColor == Color.Red) {
fragment = new MyRedFragment(mTitle, mDividerColor);
} else if (mIndicatorColor == Color.Blue) {
fragment = new MyBlueFragment(mTitle, mDividerColor);
}
return fragment;
}
You may want to introduce a different memeber than color. That could be an enum field.
Upvotes: 1