0

How can I put tabs inside of my fragment? I have been struggling with this and would greatly appreciate some help.

Currently I am getting this error: Did you forget to call 'public void setup(LocalActivityManager activityGroup)'?

However, even when I add a call to this I still get a fatal crash with an error: Must call setup() that takes a Context and FragmentManager

This seems to be contradictory....

Below is the relevant Java and XML:

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

    super.onCreateView(inflater, container, savedInstanceState);

    View v = inflater.inflate(R.layout.fragment_profile, container, false);

    mTabHost = new FragmentTabHost(getActivity());
    mTabHost.setup(getActivity().getApplicationContext(), getChildFragmentManager(), R.layout.testtabhost1);

    //LocalActivityManager mLocalActivityManager = new LocalActivityManager(getActivity(), false);
    //mLocalActivityManager.dispatchCreate(savedInstanceState); 
    //mTabHost.setup(mLocalActivityManager);

    //LocalActivityManager mLocalActivityManager = new LocalActivityManager(getActivity(), false);
    //mTabHost.setup(mLocalActivityManager);

    Intent q_intent = new Intent (getActivity(), QuestionTabActivity.class);
    Intent a_intent = new Intent (getActivity(), AnswerTabActivity.class);

    View questionIndicator = createTabView(mTabHost.getContext(), "Questions");
    View answerIndicator = createTabView(mTabHost.getContext(), "Answers");

    mTabHost.addTab(mTabHost.newTabSpec("questions").setIndicator(questionIndicator).setContent(q_intent));
    mTabHost.addTab(mTabHost.newTabSpec("answers").setIndicator(answerIndicator).setContent(a_intent));

    mTabHost.setCurrentTab(0);

    // Inflate the layout for this fragment
    return v;
}

And the XML:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.juryroom.qollege_android_v1.ProfileFragment">

    .........
    ...ETC...
    .........

    <android.support.v4.app.FragmentTabHost
        android:id="@+id/testtabhost1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/edit_profile_picture_fragment_circView"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="5dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:showDividers="none"></TabWidget>

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="match_parent">


            </FrameLayout>
        </LinearLayout>
    </android.support.v4.app.FragmentTabHost>

.........
...ETC...
.........

</FrameLayout>

Here is the design look I'm making: My Design

Community
  • 1
  • 1
Pseduosance
  • 305
  • 1
  • 5
  • 16

2 Answers2

0
mTabHost = (FragmentTabHost) v.findViewById(android.R.id.tabhost);
    mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent);
    mTabHost.addTab(mTabHost.newTabSpec(Constant.BuildingPicture.FRONT_PHOTOS).setIndicator(Constant.BuildingPicture.FRONT_PHOTOS),SiteDataFrontPhotoTab.class, null);
    mTabHost.addTab(mTabHost.newTabSpec(Constant.BuildingPicture.SATELLITE_PHOTOS).setIndicator(Constant.BuildingPicture.SATELLITE_PHOTOS),SiteDataSatellitePhotoTab.class, null);
Patel Hiren
  • 305
  • 2
  • 11
0

In order to display tabs we don’t have to use any other UI element like TabHost. Action bar has the inbuilt capability of adding tabs. All we have to do is enable it using setNavigationMode(ActionBar.NAVIGATION_MODE_TABS).

Here is a good description of what you are looking for.

Kaveesh Kanwal
  • 1,753
  • 17
  • 16