我正在制作FragmentTabHost(由FragmentActivity扩展)。
我正在尝试设置标签栏,但我遇到了一个名为No tab known for tag articulos
的错误。
这是我的java文件:
public class TabHostActivity extends FragmentActivity {
private FragmentTabHost tabHost;
private String mCurrenTab;
private HashMap<String, Stack<Fragment>> mStacks;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
tabHost.setup(this, getSupportFragmentManager(),
android.R.id.tabcontent);
inicializarTabs();
}
public void inicializarTabs() {
TabHost.TabSpec spec = tabHost.newTabSpec("articulos");
spec.setContent(new TabContentFactory() {
@Override
public View createTabContent(String tag) {
// TODO Auto-generated method stub
return findViewById(R.id.realtabcontent);
}
});
spec.setIndicator("Articulos");
tabHost.addTab(spec);
}
public void pushFragments(String tag, Fragment fragment,
boolean shouldAnimate, boolean shouldAdd) {
if (shouldAdd) {
mStacks.get(tag).push(fragment);
}
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction ft = manager.beginTransaction();
ft.replace(R.id.realtabcontent, fragment);
ft.commit();
}
}
所以,当我运行应用程序时,它会向我显示此错误:
我想我需要将Articulos class
设置为该标签?但我不知道如何。
答案 0 :(得分:3)
试试这个:
public void inicializarTabs() {
tabHost.addTab(mTabHost.newTabSpec("articulos").setIndicator("Articulos"), Articulos.class, null);
}