I'm very confused. Here it says:
nested fragments as shown in the screenshot are not possible without the support library.
and also here they said:
AFAIK, fragments cannot hold other fragments.
All this are confirmed by the Android Documentation here. So that means one thing:
You can't put Fragments into Fragments without Support v4 Library on pre API 17!
Ok, but when I have the following settings: build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 16
buildToolsVersion '19.1.0'
defaultConfig {
applicationId "package.supportfragments"
minSdkVersion 14
targetSdkVersion 16
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
MainActivity:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getFragmentManager().beginTransaction().add(R.id.frame_test, new TestFragment()).commit();
}
TestFragment:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_test, container, false);
getFragmentManager().beginTransaction().add(R.id.frame_test_2, new TestNestedFragment()).commit();
return rootView;
}
TestNestedFragment:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_test_nested, container, false);
getFragmentManager().beginTransaction().add(R.id.frame_test_3, new TestNestedNestedFragment()).commit();
return rootView;
}
The Layout looks all like that:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- TODO: Update blank fragment layout -->
<FrameLayout
android:id="@+id/IDTOTHEFRAGMENT"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
And it works like a charme... The question is.. WHY??!!