I'm getting a fragment from mother activity. Now i want to create tabs in this fragment. But tabHost.setup() method showing error. I don't get it so need a clue about error.
// FragmentOne.java
package com.example.sharelocationui;
import android.app.Fragment;
import android.os.Bundle;
import android.support.v4.app.FragmentTabHost;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView.FindListener;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.TabHost;
public class FragmentOne extends Fragment {
private FragmentTabHost tabHost;
public FragmentOne() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View v = inflater.inflate(R.layout.fragment_layout_one, container,
false);
tabHost = (FragmentTabHost) v.findViewById(R.id.testtabhost1);
tabHost = new FragmentTabHost(getActivity());
tabHost.setup(getActivity(),getChildFragmentManager(),R.id.testtabhost1);
tabHost.addTab(tabHost.newTabSpec("tab_test1").setIndicator("TAB1"));
tabHost.addTab(tabHost.newTabSpec("tab_test2").setIndicator("TAB2"));
tabHost.addTab(tabHost.newTabSpec("tab_test3").setIndicator("TAB3"));
tabHost.setCurrentTab(0);
return v;
}
@Override
public void onDestroyView() {
super.onDestroyView();
tabHost = null;
}
}
//fragment_layout_one
<android.support.v4.app.FragmentTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/testtabhost1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<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" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</FrameLayout>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
Error showing
'The method setup(Context, FragmentManager, int) in the type FragmentTabHost is not applicable for the arguments (Activity, FragmentManager, int)'
In th onCreateView method just change and remove the
to
UPDATE:
You have not initialized the FragmentTabHost.
for reference check the official example
Your problem is you are importing
not
But how to call fragment when importing android.support.v4.app.Fragment.
It is part of MainActivity.java :
It is a part of HelloTab.java :
This is perfect for your Question
and layout is: