Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android中的标签切换?_Android_Android Layout - Fatal编程技术网

android中的标签切换?

android中的标签切换?,android,android-layout,Android,Android Layout,我有如下所示的选项卡主机 private TabHost myTabHost; ...... setContentView(R.layout.vidtab); Intent intent=getIntent(); intent = new Intent().setClass(this, RecordActivityGroup.class); myTabHost = (TabHost)this.findViewById(android.R.i

我有如下所示的选项卡主机

 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 class中的按钮时切换到第二个选项卡,如何操作?我知道任何人都知道,请帮助我。

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

public void switchToTab(int tabid){
            myTabHost.setCurrentTab(tabid);
}
现在在Record类中,按一下按钮,调用此

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

我必须在哪个类中声明switchToTab()方法,无论是在tabhost中还是在RecordActivityGroups中,在您拥有
私有tabhost myTabHost;
的类中,我创建了您在tabhost类中所说的方法,然后我调用了该方法,它抛出类强制转换异常。感谢tanmay,我犯了一个小错误,很抱歉,它可以正常工作。