在android中切换切换?

时间:2011-06-02 10:31:34

标签: android android-layout

我有Tab主机,如下所示

 private TabHost myTabHost;

......    

    setContentView(R.layout.vidtab);


    Intent intent=getIntent(); 


    intent = new Intent().setClass(this, RecordActivityGroup.class);
    myTabHost = (TabHost)this.findViewById(android.R.id.tabhost);
    myTabHost.setup();
    TabSpec rectab = myTabHost.newTabSpec("Record");
    rectab.setIndicator("Record",getResources().getDrawable(R.drawable.irecord));
    rectab.setContent(intent);

    myTabHost.addTab(rectab);
   intent = new Intent().setClass(this, sharingProject.class);

    TabSpec setting = myTabHost.newTabSpec("Hint");
    setting.setIndicator("Hint",getResources().getDrawable(R.drawable.isettings));
    setting.setContent(intent);

    myTabHost.addTab(setting);

在该记录活动组中我有以下代码,

RecordActivityGroup扩展了TabGroupActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    startChildActivity("RecordingActivity", new Intent(this,Record.class));



}

和Record.class是一个包含一个按钮的活动,我需要在Record类中单击按钮时切换到第二个选项卡,该怎么做?任何人都知道请帮助我。

1 个答案:

答案 0 :(得分:1)

您可以在主类中使用方法,如下面的

public void switchToTab(int tabid){
            myTabHost.setCurrentTab(tabid);
}

现在在按钮上的Record类中点击调用此

        YourStartCalss parentActivity;
        parentActivity= (YourStartCalss) this.getParent();
        parentActivity.switchToTab(yourtabid);