ThomQ
ThomQ

Reputation: 605

Can't get Nested Fragments to work, Can't resolve getChildFragmentManager

I've been working on this problem for hours now.

My simple app displays a google map in a fragment. Upon some actions I want an fragment overlay on top of this map, so upon recieving a onClickListener event, I'm trying to run:

void addfragment() {

    Fragment placeDetails = new PlaceDetailsFragment();
    FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
    transaction.add(R.id.details, placeDetails).commit();

}

per the example at http://developer.android.com/about/versions/android-4.2.html#NestedFragments

I auto imported the following classes:

import android.app.Fragment;
import android.app.FragmentTransaction;

Every type and method could be resolved, except getChildFragmentManager. After doing some digging, I sort of had to guess that getChildFragmentManager is not part of the normal Fragment lib, but i had to install the support libraries, v4 especially. So I installed v7, which also includes the v4 jar, and went back to re-import the fragment classes:

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;

GetChildFragmentManager still can't be resolved.

I tried manually adding

import android.support.v4.app.FragmentManager;

since, getChildFragmentManager is a method of fragment that should return a FragmentManager, but still no resolving.

I feel as if i'm doing something very wrong, and googling doesn't help me much. They keep talking about moving the v4.jar to the ActionBarSherlock's lib directory, but I don't have nor need that in this project. I might get a normal Action Bar later, but I can't see why that would be needed for nested fragments.

Also, I am compiling with API 18, to a minSDKversion 18 and targetSDK version 18, so why would I even need the support library? It's a 4.2 feature, SDK 17, it should be in SDK 18 as well, correct? Wouldn't the use of the support library only be for lower SDK's, as stated in the docs?

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

What am I doing wrong? Anybody any ideas or solutions? I've been at it for hours, for over 2 days now, sanity is fleeting atm :)

Thanks in advance!

Upvotes: 0

Views: 2908

Answers (1)

Mei-Lin
Mei-Lin

Reputation: 286

Make sure you import FragmentManager from android.support.v4.app package as well.

import android.support.v4.app.FragmentManager;

I don't have the complete view of your code. Hopefully, this will resolve your problem.

Upvotes: 1

Related Questions