hcg_21 2013-02-25 08:10 采纳率: 0%
浏览 3125
已采纳

点击按钮后 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
    {

    }
}   
  }
  • 写回答

2条回答 默认 最新

  • LiDaming_and 2013-02-25 08:58
    关注

    点击按钮后,设置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条)

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作