0

Dear ladies and gents,

First of all, please do not mark my question down. If you think that my question is too stupid please let me know and i will edit it or remove.

So my actual question is that I have an activity (extends Activity). In that activity's layout I created FrameLayout where I then attach different four fragments(so each of them extends Fragment. So in one of that fragments I would like to implements swipeable tabs(see screenshot).

I know that it is usually done by implementing viewPager and FragmentPagerAdapter, but I can not do this as if I'm calling getSupportFragmentManager in my fragment it gives my an error. If i am using getActivity().getFragmentManager() it gives me error that android.support.v4.app.fragmentmanager cannot be applied to android.app.fragmentmanager. I have to use android.support.v4.app.fragment in my fragment, because otherwise I will not be able to implement my activity's view(described at the beggining).

Any ideas or suggestions would be very appreciated.screenshot

szholdiyarov
  • 385
  • 2
  • 12

3 Answers3

2

Make sure you are using Fragment class that you extends your fragments comes from support library. You also need to use FragmentActivity to call method getSupportFragmentManager();

On the other hand, viewpager which is in your fragment need to implemented as usual that you can find on internet except getChildSupportFragmentManager();

This one called "nested fragments".

PS: I am not sure but you can also use AppCompatActivity instead of FragmentActivity. FragmentActivity and ActionBarActivity must be deprecated.

Good luck

Hugo Gresse
  • 17,195
  • 9
  • 77
  • 119
Emre Aktürk
  • 3,306
  • 2
  • 18
  • 30
0

You can use getChildFragmentManager() when using Fragments inside other Fragments.

vguzzi
  • 2,420
  • 2
  • 15
  • 19
  • still giving me "android.support.v4.app.fragmentmanager cannot be applied to android.app.fragmentmanager" – szholdiyarov Oct 13 '15 at 13:07
  • i implemented my FragmentPagerAdapter by using android.support.v4.app.FragmentManager – szholdiyarov Oct 13 '15 at 13:08
  • It sounds like you're using a normal Fragment not v4 Fragment somewhere in you're app. Also make sure you are extending from FragmentActivity not Activity. The errors you are getting is saying you're getting a v4 FragmentManager which is correct but you're trying to use it when a non-v4 FragmentManager is required. – vguzzi Oct 13 '15 at 13:17
0

New version of Support Library v4 (Android 4.2) resolve this problem. For do this, simply do constructor of your custom FragmentPagerAdapter like this:

public CustomFragmentPagerAdapter(android.support.v4.app.Fragment fragment)
{
    super(fragment.getChildFragmentManager());

    // write your code here
}

This work because new Android version approve using nested Fragments

Rana Hyder
  • 75
  • 1
  • 1
  • 8