程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> tabs-點擊按鈕後 Tab 消失的問題

tabs-點擊按鈕後 Tab 消失的問題

編輯:編程綜合問答
點擊按鈕後 Tab 消失的問題

我創建了一個TabActivity類,並在程序中創建了4個tabs。本來想實現的是當我點擊按鈕時,應用程序應該移動到下一個activity類,這個類是tabs中的一個類。現在是可以移動到下一個activity類,但是 tab就消失了。

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

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
    {

    }
}   
  }

最佳回答:


點擊按鈕後,設置tab,那樣的話 tab 就不會消息,在 tab activity 設置

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

這樣的話 tabs 就會存在。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved