使用Tabhost android在第二个选项卡中显示的第一个选项卡内容

时间:2013-07-02 08:25:48

标签: android android-tabhost

我正在使用TabHost.On加载我已将第二个标签设置为默认标签。我工作正常,但随着第二个标签内容,第一个标签内容也显示。如何删除第一个选项卡内容。这仅在默认的第二个选项卡上显示,而不是在第一个选项卡上显示。

我尝试过以下代码:

 protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        // Inflate the layout
        setContentView(R.layout.tabs_viewpager_layout);

        DisplayMetrics displaymetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
        height = displaymetrics.heightPixels;
        width = displaymetrics.widthPixels;


        // Initialise the TabHost
        this.initialiseTabHost(savedInstanceState);
        if (savedInstanceState != null) {
            mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab")); //set the tab as per the saved state
        }
        // Intialise ViewPager
        this.intialiseViewPager();
        mViewPager.setCurrentItem(2);
    }

我的initialiseTabHost函数

private void initialiseTabHost(Bundle args) {

    mTabHost = (TabHost)findViewById(android.R.id.tabhost);
    mTabHost.setup();
    TabInfo tabInfo = null;
    TabsViewPagerFragmentActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab1").setIndicator("",getResources().getDrawable(R.drawable.info_icon)), ( tabInfo = new TabInfo("Tab1", Info.class, args)));
    this.mapTabInfo.put(tabInfo.tag, tabInfo);

    TabsViewPagerFragmentActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab2").setIndicator("",getResources().getDrawable(R.drawable.search_icon)), ( tabInfo = new TabInfo("Tab2", Search.class, args)));
    this.mapTabInfo.put(tabInfo.tag, tabInfo);


    TabsViewPagerFragmentActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab3").setIndicator("",getResources().getDrawable(R.drawable.home_icon)), ( tabInfo = new TabInfo("Tab3", Home.class, args)));
    this.mapTabInfo.put(tabInfo.tag, tabInfo);
    mTabHost.setCurrentTab(2); 
    TabsViewPagerFragmentActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab4").setIndicator("",getResources().getDrawable(R.drawable.member_icon)), ( tabInfo = new TabInfo("Tab4", Profile.class, args)));
    this.mapTabInfo.put(tabInfo.tag, tabInfo);
   mTabHost.setOnTabChangedListener(this);

}

有人可以帮助我吗?

谢谢,

1 个答案:

答案 0 :(得分:0)

**

主要活动:

   package com.example.tab;
   import android.os.Bundle; import android.widget.TabHost;
   import android.app.TabActivity; import android.content.Intent;







   public class MainActivity extends TabActivity{   TabHost tb1;
@Override   protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.activity_main);
            tb1=getTabHost();

tb1.addTab(tb1.newTabSpec("first").setIndicator("first1").setContent(new    Intent(MainActivity.this,first.class)));    
tb1.addTab(tb1.newTabSpec("second").setIndicator("second").setContent(new    Intent(MainActivity.this,second.class)));  




    }


   }
   first.class
   package com.example.tab;
   import android.app.Activity; import android.os.Bundle;
   public class first extends Activity{

@Override   protected void onCreate(Bundle savedInstanceState) {        //    TODO Auto-generated method stub       super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


        } }
   second.class
   package com.example.tab;
   import android.app.Activity; import android.os.Bundle;
   public class second extends Activity{

@Override   protected void onCreate(Bundle savedInstanceState) {        //    TODO Auto-generated method stub       super.onCreate(savedInstanceState);

setContentView(R.layout.main1);
        }    }