2

My classes

FragmentTabs - the fragment that will hold my FragmentTabHost

Its onCreateView method

 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {


    fragmentTabHost = new FragmentTabHost(getActivity());
    fragmentTabHost.setup(getActivity(), getFragmentManager());

    fragmentTabHost.addTab(fragmentTabHost.newTabSpec("tab1").setIndicator("Tab1"), Fragment1.class, null);
    fragmentTabHost.addTab(fragmentTabHost.newTabSpec("tab2").setIndicator("Tab2"), Fragment2.class, null);
    return fragmentTabHost;

}

The activity class XML

<RelativeLayout 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"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.studio3s.myapplication.TestActivity">


<fragment
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:name="com.studio3s.myapplication.FragmentTabs"
    android:id="@+id/fragment"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true" />

I see no tabs on my activity..where can be the problem?

Fragment1 and 2 classes are just empty fragments with just one textview..

Boldijar Paul
  • 5,405
  • 9
  • 46
  • 94

1 Answers1

3

use childFragmentManager instead FragmentManager i.e.

fragmentTabHost.setup(getActivity(), getChildFragmentManager(), R.id.content);

Here conent is where you want to shown current fragment. now your container will contains tabs which you add in fragmentTabHost

Pravin
  • 1,362
  • 12
  • 21
  • Changed to fragmentTabHost.setup(getActivity(), getChildFragmentManager(),R.id.content); in my fragmentTabs class, and edited the fragment xml to http://pastebin.com/RnXBaV62 . Still, nothing.. And also, the onAttach function is called for my FragmentTabs class.. – Boldijar Paul Oct 10 '14 at 13:32
  • my suggestion is to use `FrameLayout` in case of `LinearLayout` – Pravin Oct 10 '14 at 13:43
  • Same output..http://pastebin.com/qUj8YEHm..Do you know any tutorials to do something like this http://2.bp.blogspot.com/-9U6gX0XYC5Y/UZ92L8HpLJI/AAAAAAAATiU/eRzkdGVLLSw/s1600/sample1.png , but not with actionbar.. I want to do this inside a fragment.. – Boldijar Paul Oct 10 '14 at 13:47
  • Nevermind.. I followed this tutorial http://maxalley.wordpress.com/2013/05/18/android-creating-a-tab-layout-with-fragmenttabhost-and-fragments/ , and after 3 hours everything is ok! haha! Thanks for you help anyways! – Boldijar Paul Oct 10 '14 at 14:03