单击按钮后标签消失

时间:2011-06-08 05:07:29

标签: android tabs

我创建了TabActivity类,我在其中为我的应用程序创建了四个选项卡。现在,当我点击按钮时,我的应用程序将移动到我的选项卡中已经存在的下一个活动类。发生了什么我能够移动到下一个活动类但我的选项卡正在消失。所以,任何人都可以告诉我该怎么做。

private OnClickListener Btn_Listener_Continue = new OnClickListener()
{
    public void onClick(View v)
            {

    // TODO Auto-generated method stub
        Intent edit = new Intent(v.getContext(), RoomEdit.class);
            startActivityForResult(edit,0);
         TabForConfiguration.spec.setCurrentTab(1); 
    }             
};

我已经删除了公共静态TabHost规范;在我的TabActivity类中,应用程序仍在崩溃。

这是我的TabActivity类。

 public class TabForConfiguration extends TabActivity {

 private Bundle bundle;      
 public static TabHost tabHost;      
 private TabHost.TabSpec tab1,tab2,tab3,tab4;     
 private Intent intentToTabOne,intentToTabtwo,intentToTabthree,intentToTabfour;      
 private int i=0,flagForTab,flagTest;     
 public int setTab=0,currentTabset;  

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    try{
    // request is for a window
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.tab_for_configuration);
    Resources res = getResources();// resource for drawable
    tabHost = getTabHost(); // add tabs to tab host

    bundle = TabForConfiguration.this.getIntent().getExtras();                 
    setTab = bundle.getInt("setTab");                 
    flagTest = bundle.getInt("flag");                  

    if(flagTest == 0)                 
    {                     
        intentToTabOne= new Intent(TabForConfiguration.this,OwnerConfiguration.class);                     
        intentToTabOne.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);                 
    }  

    intentToTabtwo= new Intent(TabForConfiguration.this,RoomEdit.class);                 
    intentToTabthree= new Intent(TabForConfiguration.this,UserCreate.class);                 
    intentToTabfour= new Intent(TabForConfiguration.this,UserAccessRight.class); 
    //TabHost.TabSpec spec;

//  intent = new Intent().setClass(this, OwnerConfiguration.class);
    tab1 = tabHost
            .newTabSpec("Initializer")
            .setIndicator("Home_Configure",
                    res.getDrawable(R.drawable.config_home))
            .setContent(intentToTabOne);
    tabHost.addTab(tab1);

    tab2 = tabHost
            .newTabSpec("Room Edit")
            .setIndicator("Room_Edit",res.getDrawable(R.drawable.room_edit))
            .setContent(intentToTabtwo);
    tabHost.addTab(tab2);

    tab3 = tabHost
            .newTabSpec("User Create")
            .setIndicator("User_Create",res.getDrawable(R.drawable.user_info))
            .setContent(intentToTabthree);
    tabHost.addTab(tab3);

    tab4 = tabHost.newTabSpec("Room Access")
            .setIndicator("Room_Right", res.getDrawable(R.drawable.right))
            .setContent(intentToTabfour);
    tabHost.addTab(tab4);




if(setTab == 0)                 
{                     
    currentTabset = 0;                     
    tabHost.setCurrentTab(currentTabset);                 
}                 
else if(setTab == 1)                 
{                     
    currentTabset = 1;                     
    tabHost.setCurrentTab(currentTabset);                 
}                 
else if(setTab == 2)                 
{                     
    currentTabset = 2;                     
    tabHost.setCurrentTab(currentTabset);                 
}                 
else if(setTab == 3)                 
{                     
    currentTabset = 3;                     
    tabHost.setCurrentTab(currentTabset);                 
}                 
else if(setTab == 4)                 
{                     
    currentTabset = 4;                     
    tabHost.setCurrentTab(currentTabset);                 
} 
    }

    finally
    {

    }
}   
  }

3 个答案:

答案 0 :(得分:1)

单击按钮后设置该选项卡。因此该选项卡不会消失。 同样在标签活动集

 public static TabHost tabHost;` 
 Button b1 = new Button(this);
b1.setOnClickListener(new OnClicklistener()  
{
public void onClick(View v) 
                {
Tabs.tabHost.setCurrentTab(1);
}
});

现在你的标签会出现在那里。标签是我的选择。

答案 1 :(得分:0)

您要找的是ActivityGroups。如果要在显示选项卡的情况下加载下一个活动,则必须使用ActivityGroups。您不能使用活动。

Check this

link

答案 2 :(得分:0)

    private Bundle bundle;

    public static TabHost tabHost;

    private TabHost.TabSpec tab1,tab2,tab3,tab4;

    private Intent intentToTabOne,intentToTabtwo,intentToTabthree,intentToTabfour;

    private int i=0,flagForTab,flagTest;
    public int setTab=0;

    public void onCreate(Bundle savedInstanceState) 
    {
        try
        {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.tabs);

                tabHost = getTabHost();
                res = getResources();

                bundle = Tabs.this.getIntent().getExtras();
                setTab = bundle.getInt("setTab");
                flagTest = bundle.getInt("flag");

                if(flagTest == 0)
                {
                    intentToTabOne= new Intent(Tabs.this,BusinessType.class);
                    intentToTabOne.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                }   


                intentToTabtwo= new Intent(Tabs.this,act1.class);
                intentToTabthree= new Intent(Tabs.this,act2.class);
                intentToTabfour= new Intent(Tabs.this,act3.class);

                tabMenuList = tabHost.newTabSpec("Menu")
                                     .setIndicator("Menu List",res.getDrawable(R.drawable.icon))
                                     .setContent(intentToTabOne);

                tabFavourite    = tabHost.newTabSpec("Favourite")
                                     .setIndicator("Favourite",res.getDrawable(R.drawable.icon))
                                     .setContent(intentToTabtwo);

                tabDeal = tabHost.newTabSpec("Deal of the Day")
                                         .setIndicator("Deal of the Day",res.getDrawable(R.drawable.tab_deal))
                                         .setContent(intentToTabthree);

                tabLockedDeals  = tabHost.newTabSpec("Locked Deals")
                                     .setIndicator("Locked Deals",res.getDrawable(R.drawable.icon))
                                     .setContent(intentToTabfour);

                tabHost.addTab(tabMenuList);
                tabHost.addTab(tabFavourite);
                tabHost.addTab(tabDeal);
                tabHost.addTab(tabLockedDeals);



                if(setTab == 0)
                {
                    currentTabset = 0;
                    tabHost.setCurrentTab(currentTabset);
                }
                else if(setTab == 1)
                {
                    currentTabset = 1;
                    tabHost.setCurrentTab(currentTabset);
                }
                else if(setTab == 2)
                {
                    currentTabset = 2;
                    tabHost.setCurrentTab(currentTabset);
                }
                else if(setTab == 3)
                {
                    currentTabset = 3;
                    tabHost.setCurrentTab(currentTabset);
                }
                else if(setTab == 4)
                {
                    currentTabset = 4;
                    tabHost.setCurrentTab(currentTabset);
                }

来自

Button b1 = new Button(this);
b1.setOnClickListener(new OnClicklistener()  
{
public void onClick(View v) 
                {
Tabs.tabHost.setCurrentTab(1);
}
});