开发者

Tab switching in android?

i have Tab host which is shown below,

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

in that record Activity group i have following code,

RecordActivityGroup extends TabGroupActivity{

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    startChildActivity("RecordingActivi开发者_如何学编程ty", new Intent(this,Record.class));



}

and Record.class is an activity which contain one button, i need to switch to second tab while clicking button in Record class, how to do that? i any one know that please help me out.


You can use an method in your main class like following

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

And now in Record class on your Button click call this

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜