首先在孩子的父母上调用removeView()??

时间:2014-06-13 11:53:22

标签: java android view android-fragmentactivity fragment-tab-host

@ Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.bottom_tabs);

    ActionBar actionBar = getActionBar();

    // set the Icon
    actionBar.setIcon(R.drawable.ic_launcher);

    mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup(this , getSupportFragmentManager() , R.id.realtabcontent);

    tabIndicator1 = LayoutInflater.from(this).inflate(R.layout.apptheme_tab_indicator_holo , mTabHost.getTabWidget() , false);
    title = (TextView) tabIndicator1.findViewById(android.R.id.title);
    title.setText("Infos");

    tabIndicator2 = LayoutInflater.from(this).inflate(R.layout.apptheme_tab_indicator_holo , mTabHost.getTabWidget() , false);
    title = (TextView) tabIndicator2.findViewById(android.R.id.title);
    title.setText("Info");

    tabIndicator3 = LayoutInflater.from(this).inflate(R.layout.apptheme_tab_indicator_holo , mTabHost.getTabWidget() , false);
    title = (TextView) tabIndicator3.findViewById(android.R.id.title);
    title.setText("Development");

    tabIndicator4 = LayoutInflater.from(this).inflate(R.layout.apptheme_tab_indicator_holo , mTabHost.getTabWidget() , false);
    title = (TextView) tabIndicator4.findViewById(android.R.id.title);
    title.setText("Charging");

    mTabHost.addTab(mTabHost.newTabSpec("infos").setIndicator(tabIndicator1) , InformationTabs.class , null);
    mTabHost.addTab(mTabHost.newTabSpec("info").setIndicator(tabIndicator2) , InfoFragment.class , null);
    mTabHost.addTab(mTabHost.newTabSpec("development").setIndicator(tabIndicator3) , DevelopmentTab.class , null);
    mTabHost.addTab(mTabHost.newTabSpec("charging").setIndicator(tabIndicator3) , ChargingTab.class , null);

}

LogCat表示指定的孩子已经有父母。我应该首先在孩子的父母身上调用removeView()......

我只是不明白?!

我知道问题在于我在这里使用2个布局,但我该如何解决呢....

感谢任何提示

1 个答案:

答案 0 :(得分:0)

当您尝试将视图添加到父级并且已将其添加到另一个父级时,会发生此类错误。

您已添加tabIndicator3两次。替换此代码:

mTabHost.addTab(mTabHost.newTabSpec("charging").setIndicator(tabIndicator3) , ChargingTab.class , null);

由此:

mTabHost.addTab(mTabHost.newTabSpec("charging").setIndicator(tabIndicator4) , ChargingTab.class , null);