Hide Fragment Tab Host tabs within the child fragm

2019-08-20 11:23发布

问题:

I have an android project where I use the navigation drawer. Within that I have a fragment called "agenda". This fragment is a fragment tabhost (see layout below and class below). Within this fragment tabhost I have three tabs ("Friday", "Saturday", and "Sunday").

I have a single fragment with a listview of sessions that I use to populate the Friday, Saturday, Sunday tabs with different data -- depending on which tab is selected.

On click of a listview item, I want to navigate to a details page (session details) for the item selected.

MY ISSUE:

I am able to pass the correct arguments to populate session details. However, on navigating to session details page I still see the tabs at the top of the screen. Thus, when I click on one of the tabs ---i.e. Saturday (while on session details) the listview for Saturday populates over the current session details page I am on.

WHAT I EXPECT:

Ideally, what I want is when navigating to session details, I want to completely navigate out of the tab host (I do not want to see the tabs at the top of the session details page). Instead of the tabs showing, I want to be able to add a back button on session details so on click of back I navigate back to the agenda page that shows the day tabs.

MY AGENDA HOST LAYOUT

<FrameLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/agendahost"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<TabHost
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/agenda_tabHost"
    android:layout_gravity="center_horizontal">

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

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
        </TabWidget>

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

            <LinearLayout
                android:id="@+id/friday"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="horizontal">

            </LinearLayout>

            <LinearLayout
                android:id="@+id/saturday"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="horizontal">

            </LinearLayout>

            <LinearLayout
                android:id="@+id/sunday"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="horizontal">

            </LinearLayout>

        </FrameLayout>
    </LinearLayout>
</TabHost>
</FrameLayout>

AGENDA HOST FRAGMENT - ON CREATE VIEW

    final Bundle args = new Bundle();

    {

        agendaTabHost = new FragmentTabHost(getActivity());
        agendaTabHost.setup(getActivity(), 
getChildFragmentManager(), R.id.fragment_container);

        //CODE ADDING TABS FOR EACH DAY




        return agendaTabHost;
    }

AGENDA FRAGMENT - The fragment I use to populate each tab depending on tab selected. Below is my listview click code

    listView.setOnItemClickListener(new 
    AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, 
    int position, long id) {

            SessionDetailsFragment sessiondetFrag = new 
    SessionDetailsFragment();


            Bundle args = new Bundle();



            // CODE TO PASS SESSION ARGUMENTS DEPENDING ON ITEM CLICK ON LISTVIEW  

getFragmentManager(). 
beginTransaction().replace(R.id.fragment_container, 
sessiondetFrag).addToBackStack(null).commit();



        }
    }