开发者

Tab are dissapring after click on button

开发者 https://www.devze.com 2023-03-11 08:51 出处:网络
I have created TabActivity class in which i am creating four tabs for my application. Now when i click on button my application sould move to next activity class which is already present in my tabs al

I have created TabActivity class in which i am creating four tabs for my application. Now when i click on button my application sould move to next activity class which is already present in my tabs also.What is happening i am able to move to next activity class but my tab are disspering. So please can anyone tell how can i do this.

private OnClickListener Btn_Listen开发者_如何学Goer_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); 
    }             
};

And I have decleared public static TabHost spec; in my TabActivity class still application is crashing.

This is my TabActivity Class.

 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
    {

    }
}   
  }


after click on button set that tab.So that tab will not disappeared. Also in tab activity set

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

Now your tabs will present there. Tabs is my tabactivity.


What you are looking for is ActivityGroups. If you want your next activity to be loaded with your tabs being displayed you have to use ActivityGroups. You can't use Activities for this.

Check this

link


    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);
                }

And from

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号