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条)

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题