I used below code and it is not render graphical layout. display error as Exception raised during rendering: No tab known for tag null.
how can i solve
My develop environment is Android Studio 0.8.9 with API19 SDK.
If I put the FragmentTabHost in a FragmentActivity, it works. When I put the FragmentTabHost in a Fragment, it gets "no tab known for tag null" when render and get runtime error when LayoutInflater inflate the layout.
Thank for user3216049's answer, it's a good workaround. Sorry, I cannot vote since I am a newbie. :(
However it display nothing in my test tab fragments. I did a small modification.
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTabHost;
public class TestFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
FragmentTabHost tabHost = new FragmentTabHost(getActivity());
inflater.inflate(R.layout.test_fragment, tabHost);
tabHost.setup(getActivity(),
getChildFragmentManager(), R.id.realtabcontent);
tabHost.addTab(tabHost.newTabSpec("simple")
.setIndicator("Simple"), DummySectionFragment.class, null);
tabHost.addTab(tabHost.newTabSpec("contacts")
.setIndicator("Contacts"), DummySectionFragment.class, null);
return tabHost;
}
/**
* A dummy fragment representing a section of the app,
* but that simply displays dummy text.
*/
public static class DummySectionFragment extends Fragment {
private static int count = 0;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_section_dummy,
container, false);
((TextView) rootView.findViewById(android.R.id.text1))
.setText("Dummy Section " + count++);
return rootView;
}
}
}