0

我正在使用 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);

}

有人可以帮我吗?

谢谢,

4

1 回答 1

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);
        }    }
于 2013-07-02T08:55:05.807 回答