you don't need to use onCreateView ()
You can:
1) define the application layout and fragments in your xml activity, for example:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" ..blabla <LinearLayout <fragment android:layout_width="match_parent" android:layout_height="wrap_content" android:name="com.xxx.MyPreferencesFragment1" //your own extended class android:id="@+id/preference_fragment1"/> <fragment android:name="com.xxx.MyPreferencesFragment2" //your own extended class android:id="@+id/preference_fragment2"/> </LinearLayout> </RelativeLayout>
from
public class MyPreferencesFragment1 extends PreferenceFragment {
OR you can:
2) only the linker / container ("R.id.fragments_layout") is defined in the xml operation, and the rest are from java code
<LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/fragments_layout">
and cc now you also need to inflate the XML preferences file inside this layout container
getFragmentManager().beginTransaction().replace/add(R.id.fragments_layout, new MyPreferencesFragment1()).commit(); getFragmentManager().beginTransaction().replace/add(R.id.fragments_layout, new MyPreferencesFragment2()).commit();
Noam geffen
source share