I have managed to add TabHost
on my fragment
but when i click on one tab i want another fragment
to come in FrameLayout
, same goes to another.
I have tried applying the method but it does not work in setup host.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent)
.
What can be done to solve this issue ?
Here is my XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TabHost
android:id="@+id/tabHost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
<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="30dp" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:id="@+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
</FrameLayout>
</LinearLayout>
<FrameLayout
android:id="@+id/realtabcontent"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@+id/tabLinear"
/>
</TabHost>
</RelativeLayout>
Here is my Java Code:
public class HomeFragment extends Fragment {
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_home,
container, false);
TabHost host = (TabHost) view.findViewById(R.id.tabHost);
host.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent);
host.addTab(host.newTabSpec("tab11").setIndicator("Tab11"), PhotosFragment1.class, null);
host.addTab(host.newTabSpec("tab22").setIndicator("Tab22"), PhotosFragment2.class, null);
return view;
}
}